0

After updating to PHP 7.2 mysqli_query() returns false but not displaying error when I use mysqli_error()

I changed the functions to the updated versions. Mysqli_query function or Mysqli_error seems not working proper or not error but It does not display the database content and mysqli_query return false.

<?php
$conex=mysqli_connect('dburl','dbuser','dbpass', 'dbname');
if ($conex == false) {
    echo mysqli_errno().': '.mysqli_connect_error();
    exit();
}

$query2 = "SELECT * FROM `opiniones`";
$resul2 = mysqli_query($query2, $conex);
if ($resul2 == false) {
    echo "Error:<br>".mysqli_errno($conex).': '.mysqli_error($conex)."<br />";
    echo "Not entering opiniones.<br />";
}
while ($fila2 = mysqli_fetch_array($resul2)) {
    echo $fila2['autor'];
}
mysqli_free_result($resul2);
?>
Ernesto
  • 1
  • 3

1 Answers1

1

Your first problem is that you do not check if the connection was successful. To check the connection error you can use mysqli_connect_error

Your second issue is that you have the reverse order of arguments passed to mysqli_query It should be:

$resul2 = mysqli_query($conex, $query2);

You should also consider switching MySQLi exception mode on

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • Solved! That was the problem. Thanks a lot! – Ernesto Jun 02 '19 at 22:55
  • How come you were not receiving any errors from PHP? Are you sure that you have error_reporting switched on? – Dharman Jun 02 '19 at 22:56
  • After updating php versión might be disabled, but it is uploaded through a hosting company and It seems don't have access to php.ini file. – Ernesto Jun 02 '19 at 23:09