简体   繁体   中英

Why PDO connection sowing “SQLSTATE[HY000]: General error”?

I am using pdo connection. I am trying to run a delete query but it is showing this message in the browser

     *SQLSTATE[HY000]: General error*

Here is my query:

      $user_id = $_POST['user_id'];  $result = query($conn, "DELETE  FROM user WHERE user_id = '$user_id'");

I don't know why happening this. Any kind of help will be appreciated.Thanks

I think there is a query() function does not exists in PHP .. It should be mysql_query or mysqli_query

Using Mysql query is bad because it is depreciated in Updated version of php

$result = mysqli_query($conn, "DELETE  FROM user WHERE user_id = '$user_id'");

//So using mysqli :) 

$result = mysqli_query($conn, "DELETE  FROM user WHERE user_id = '$user_id'");

Per MySQL 5.5.35 source code, sql/sql_prepare.cc :

bool
Reprepare_observer::report_error(THD *thd)
{
  /*
    This 'error' is purely internal to the server:
    - No exception handler is invoked,
    - No condition is added in the condition area (warn_list).
    The diagnostics area is set to an error status to enforce
    that this thread execution stops and returns to the caller,
    backtracking all the way to Prepared_statement::execute_loop().
  */
  thd->stmt_da->set_error_status(thd, ER_NEED_REPREPARE,
                                 ER(ER_NEED_REPREPARE), "HY000");
  m_invalidated= TRUE;

  return TRUE;
}

It appears that your error (SQL state HY000) will happen when there is a wrong sequence of prepare/execute statements. Double-check our logic to make sure you are properly using prepared statements, eg properly fetching all of the results after the call to query() before calling it again.

If you cannot figure it out, isolate the problem to a minimal, complete, and verifiable example ( https://stackoverflow.com/help/mcve ), and post the code here.

UPDATE:

Does the problem go away (or do you at least get a meaningful error message) if you do

$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); 

prior to the query?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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