Really, it drive me crazy when I can't detect what error that happens. I can't handle it.
I managed to make a connection to MySQL, and check it out with:
$connection = mysqli_connect(HOST, USER, PASS, DB) or die('Could not connect!');
if($connection){
echo 'It's connected!';
}
Yeah, that say connected. Then, when I try a query, it fails without error reporting. I've tried do this to check if it fails:
$query = "SELECT $field FROM users WHERE id = ".$_SESSION['user_id'];
$result = mysqli_query($dbc, $query);
if($result){
echo 'Query OK';
}else{
echo 'Query failed';
}
The browser said: Query failed. So, there's an error in my query. Then I echoed the query out with this:
echo $query;
// Printed in the browser: SELECT firstname FROM users WHERE id = 1
Copy that value and use it in phpMyAdmin. It works. So, i guess an error occured in mysqli_query
function. But i can't get the error message and so i don't know what's going on. I've tried this:
$result = mysqli_query($dbc, $query) or die(mysqli_error($dbc));
and this:
if(!$result){
echo mysqli_error($dbc);
}
Nothing happens. The browser just blank. Then, I tried to change this:
$result = mysqli_query($dbc, $query);
to this:
$result = mysqli_query($query);
Still nothing happens. What's going on? How can I know what error occured?
I run the server in Debian with phpinfo()
: PHP Version 5.4.36-0+deb7u3