php - PDO - Invalid parameter number -


I have recently switched to use in PDF / PHP / MySQL and changed dozens of questions . Most of them used to work, though it is very easy $ sql-> execute ()

  $ sql = $ pdo-> Ready ("user name", $ user name); (Sql- & gt; User ID); $ Sql- & gt;;);   

PDOStatement :: execute () pdostatement.execute SQLSTATE [HY093]: Invalid parameter number: Number of bound variables does not match token number ...

After the research, I found this link:

... and therefore

  $ sql = $ pdo-> tried to change the query; ("selection" id From 'User' Where 'Username' =: Uses The name of the recipient is 1) "; $ Sql-> Act (array: 'username:', $ user name);   

But still with the same result. Someone sees whether it is clearly wrong or why this question does not work when all others did?

Thank you very much!

': Username', $ Username works only in BindParam () method:

  $ Sql-> BindParam (': Username', $ User Love, PDO :: Param_st); Take a look here:  

You need a right array of input-only values ​​to execute:

  $ Sql ​​- & gt; Execution (array (': user name' = & gt; $ username));  Placeholder:   

You can also use it:

  $ sql-> ; Execute (array ($ username));   

But for this, you need to change your query to:

  $ sql = $ pdo- & gt; Prepare ("Select 'id' to 'user' WHERE 'user name' =? LIMIT 1");   

What? Works as a pillillar and takes the variable from the array. When you use more placeholders in your SQL statement, the function takes all the variables out of the order in order.

Comments