Display mysqli error using die

1

I used mysql_query , as it is not used anymore I am using MySQLi .

With this I was left with a doubt.

To display the query error by DIE is this how it is done?

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

Thank you.

    
asked by anonymous 06.01.2016 / 15:55

1 answer

2

Avoid mixing the procedural and OO style of MySQLi, maintain consistency

In object-oriented the correct way is through the $ error property

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

Non-procedural you are required to pass the connection to the function:

$sql = mysqli_query($conexao, "SELECT * FROM tabela") or die(mysqli_error($conexao);
    
06.01.2016 / 16:56