Mysqli_error() does not work

2019-07-21 02:42发布

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.

标签: php mysql mysqli
2条回答
霸刀☆藐视天下
2楼-- · 2019-07-21 03:11

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.

查看更多
smile是对你的礼貌
3楼-- · 2019-07-21 03:12

Try to this..

$dbnm = "magnificantDatabase";

$abc= mysqli_connect("localhost","root","root") or die ("could not connect to mysql");     
mysqli_select_db($abc,$dbnm) or die ("no database");

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

mysqli_query($dbc, $sql) or die(mysqli_error($dbc));
查看更多
登录 后发表回答