Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysqli_error() does not work

Tags:

php

mysql

mysqli

The following code:

  $dbc = mysqli_connect("localhost","root","root","magnificantDatabase")
  or die("Could not connect to database");

  $sql = "INSERT INTO accounts(username, password, ip)
  VALUES('$username','$password','$ip')";

  mysqli_query($dbc, $sql)
  or die(mysqli_error($dbc));

Should return an error when the mysqli_query fails return an error, shouldn't it? It doesn't though :/ Anyone have any ideas why it doesn't?

Oh and, by returning no error I mean it returns nothing at all. just completely blank.

Edit: I'd like to let you know that after having searched the web (even though as this would seem a common problem) I have -NOT- found anything that fixes this, there are issues close to this one, but none of them I have found appear to be the exact same.

like image 282
Bob Desaunois Avatar asked Jul 09 '13 23:07

Bob Desaunois


1 Answers

Same thing happened to me when I executed an UPDATE statement.

mysqli_error, mysqli_errno and mysqli_error_list were all empty.

Then I discovered that the problem was that the database user assigned to the connection object did not have the UPDATE privilege. I don't know why I did not receive an error message or an error number for this security/privilege breach.

like image 193
Ramon Saguna Avatar answered Sep 17 '22 17:09

Ramon Saguna