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

后端 未结 1 1104
醉酒成梦
醉酒成梦 2021-01-28 09:14

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?

1条回答
  •  走了就别回头了
    2021-01-28 10:01

    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.

    0 讨论(0)
提交回复
热议问题