问题
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