Record an outsourced php problem: the query method is not executed

$sql="**********"
$re=$conn->query($sql);

I encountered a problem this time. The above code does not execute. There are many problems, and the answers given by gpt are also very rich.

In PHP, the query() method is the method used to execute SQL query statements. If the method is not executed, it may be due to the following reasons:

  1. Incorrect SQL query statement: If the SQL query statement has syntax errors or logical errors, the query() method will not execute. You can check whether the SQL query statement is correct by printing the SQL query statement or using other debugging tools.
  2. Database connection failure: If the database connection fails, the query() method will fail to execute. You can check that the database connection parameters are correct, or use other methods to test that the database connection is working.
  3. PHP version problem: If your PHP version is too low, the query() method may fail to execute. You can try to upgrade the PHP version or use other methods to execute the SQL query statement.
  4. Permission issue: If you do not have sufficient permission to execute the SQL query statement, the query() method will not execute. You can check that the database user permissions are correct, or use other methods to execute SQL queries.

Solution:

$sql="**********"
$re=$conn->query($sql);
if(!$re){
echo $conn->error; // 打印错误代码
}

Guess you like

Origin blog.csdn.net/qq_35230125/article/details/130550290