I've googled this issue, and seems there are a variety of reasons that this occurs. I have the following code which ruled out most of the top reasons I saw:
$conn = new mysqli($DBServer, $DBUser, $DBPass, $DBName);
// check connection
if ($conn->connect_error) {
trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR);
}
if (function_exists('mysqli_query')) {
print('installed');
}
else{
print('not installed');
}
$sqlQuery="SELECT fname FROM `lists_users` WHERE `id`='2'";
echo $sqlQuery;
// Execute Query -----------------------------
$result = mysqli_query($conn, $sqlQuery);
if(!$result) {
echo "Cannot do query" . "<br/>";
exit;
}
$row = mysqli_fetch_row($result);
$count = $row[0];
if ($count > 0) {
echo "Query works";
} else {
echo "Query doesn't work" ."<br/>";
}
The result from above code that I get is, Mysqli "installed", and "Query doesn't work". I can copy and paste the echoed above sql query into phpMyAdmin, and it will return a row.
Really really stumped as to what the issue could possibly be.
So at the suggestion of YourCommonSense, I put in error reporting. and the error I get is 'mysqli class not found'.
So did some more googling, and tried this code:
if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) {
echo 'We don\'t have mysqli!!!';
} else {
echo 'Phew we have it!';
}
....and it returns 'Phew we have it!' :\
AND I can run "php -r "new mysqli();" from the commmand line and it works.