Prepared statement expects 0 params with 1 given .., using php manual example

倾然丶 夕夏残阳落幕 提交于 2019-12-20 06:57:53

问题


I took this straight from php manual example -- it was almost identical to what I needed but I am still getting this error.

Can someone tell me what I am missing?

$stmt = $link->prepare("SELECT obitBody, Photo FROM tnObit WHERE obitID = ?");
if ($stmt->execute(array($_POST['obitID']))) {
  while ($row = $stmt->fetch()) {
    print_r($row);
  }
}

mysqli_stmt::execute() expects exactly 0 parameters, 1 given in


回答1:


execute (the object-based one, as opposed to the older less-favored variant) doesn't actually take any parameters.

From your query and attempted parameters to execute, it looks like you're trying to pass the needed parameters as an array to the execute call. This is not how it's done.

You need to bind variables to the ? markers in a separate call before calling execute.

This question (once fixed with the accepted answer) shows the general process you need to follow:

  • create statement;
  • prepare statement;
  • bind parameters;
  • execute (with no parameters);
  • store result (if buffering);
  • bind result variables;
  • fetch (in loop, most likely);
  • close statement.


来源:https://stackoverflow.com/questions/18604205/prepared-statement-expects-0-params-with-1-given-using-php-manual-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!