I am trying to host my own web on PR4100 NAS MyCloud, i had already gone through all the symlink stuff, so that’s over and kicking.
Now i am facing another problem while coding my own simple php page.
I needed to access mySQL via php to retrieve data but it appears that i couldn’t do so without 500 Internal Server Error.
I’m not sure where went wrong because i couldn’t find the Error.log file that would show me my errors.
But as I remarked the codes line by line, i found out it started with $conn = new mysqli($servername, $username, $password, $dbname);
From what i can guess, its that the mysqli doesnt exist.
But how would WordPress and other apps connect to MySQL if it doesn’t work?
Is it possible that I need to activate it during the start.sh ?
Here’s a tiny code below and do let me know if I’ve missed something.
<?php
header("Access-Control-Allow-Origin: *");
//Setup and filter all inputs and variables
$method = $_SERVER['REQUEST_METHOD'];
$u = isset($_POST['u']) ? $_POST['u'] : null;
$p = isset($_POST['p']) ? $_POST['p'] : null;
//Do works
if($method == 'POST')
{
if(($u != null) && ($p != null))
{
$servername = "localhost";
$username = "test";
$password = "1234";
$dbname = "mydb";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM users";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc())
{
print_r($row);
}
} else {
echo "0 results";
}
$conn->close();
//202 ACCEPTED
http_response_code(202);
}else
{
//[X] 400 BAD REQUEST
http_response_code(400);
}
}
else
{
//[X] 400 BAD REQUEST
http_response_code(400);
}
?>
Many thanks in advance.