简体   繁体   English

MYSLI_QUERY返回false,但从5.6更新php 7.2后,MYSQLI_ERROR不显示错误

[英]MYSLI_QUERY return false but MYSQLI_ERROR not displaying error after updating php 7.2 from 5.6

After updating to PHP 7.2 mysqli_query() returns false but not displaying error when I use mysqli_error() 更新到PHP 7.2后,当我使用mysqli_error()时mysqli_query()返回false,但不显示错误

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. Mysqli_query函数或Mysqli_error似乎不能正常工作或没有错误,但是它不显示数据库内容,并且mysqli_query返回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);
?>

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 要检查连接错误,可以使用mysqli_connect_error

Your second issue is that you have the reverse order of arguments passed to mysqli_query It should be: 第二个问题是传递给mysqli_query的参数的顺序相反,应该是:

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

You should also consider switching MySQLi exception mode on 您还应该考虑打开MySQLi异常模式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM