Display mysqli error using die

Asked

Viewed 2,994 times

2

Wore mysql_query, as it is no longer used I am using the MySQLi.

That left me with a question.

To display query error by DIE that’s how you do it?

$sql = $mysqli->query("SELECT * Fron tabela") or die(mysqli_error();

Thank you.

  • 5

    We’re missing a ) before the ;, but the concept is the same.

  • 1

    Exchange tbm this "Fron". The correct SQL syntax is "From"

  • 3

    @Diegodesouzasilva, curiously, the fron there may be purpose to cause the error and see if the mysqli_error() works :P haha

  • 1

    hahaah is even believe kkk, had not even called me kkk

  • @rray still someone edited and was approved...

1 answer

5

Avoid mixing Mysqli procedural and OO style, maintain consistency

In object oriented the correct form is through the property $error

$sql = $mysqli->query("SELECT * FROM tabela") or die($mysqli->error);

In the procedural you are required to pass the connection to the function:

$sql = mysqli_query($conexao, "SELECT * FROM tabela") or die(mysqli_error($conexao));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.