0

I have been beating my brain in trying to figure how to convert this to mysqli.

die( mysql_error().'<br /><br />' . $query.'<br /><br />

I have tried putting the connection string between the parens, and that just isn't cutting it.

die( mysqli_error($GLOBALS['CONN']).'<br /><br />' . $query.'<br /><br />

I get

PHP Catchable fatal error: Object of class mysqli could not be converted to string.

I'm a PHP newb, and cannot figure what I am missing here.

u_mulder
  • 54,101
  • 5
  • 48
  • 64

1 Answers1

0

From the mysqli documentation the syntax is

Object oriented style

string $mysqli->error;

Procedural style

string mysqli_error ( mysqli $link )

So depending on your programming style you have either something like
$mysqliObj = new mysqli( ... ); or $link = mysqli_connect( ... ) in your code. Depending on this you have to use either

$mysqsliobj->error

or

mysqli_error($link)

Just a few comments on this:

  • You should not use this in production. If there is an error in your Query or the Database is offline you don't want to print the whole query to the user. Maybe this query is containing something that should not be public.
  • You also don't want to stop the execution at this exact point. Just catch the error, write it into a log file and show a useful error message to the user.
Community
  • 1
  • 1
AbcAeffchen
  • 14,400
  • 15
  • 47
  • 66