These days I'm switching from a Windows system to Linux. I installed the LAMP stack, and apparently there seems to be no malfunctions. To be sure I wrote a trite script that connects to the database and performs a simple select query.
phpconnect.php:
<html>
<head>
<title>Test PHP Connection Script</title>
</head>
<body>
<h3>PHP Connect Test</h3>
<?php
$dbname = 'test';
$dbuser = 'my_user';
$dbpass = 'my_password';
$dbhost = 'localhost';
// connection to db
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
// check connection
if ($conn->connect_errno) {
echo "Failed to connect to MySQL: " . $conn->connect_error;
exit();
}
$sql = "SELECT * FROM user";
$result = $conn->query($sql);
$row = $result->fetch_array();
printf("%s %s (%s)\n", $row["firstname"], $row["lastname"], $row["age"]);
I checked log file in /var/log/apache2/error.log
and this is the error that comes up:
PHP Fatal error: Uncaught Error: Call to a member function fetch_array() on bool in /var/www/html/phpconnect.php:28\nStack trace:\n#0 {main}\n thrown in /var/www/html/phpconnect.php