note 108023 added to mysqli-stmt.prepare
| From: | logos-php at kith dot org | Date: | Fri, 23 Mar 2012 07:06:17 +0000 |
| Subject: | note 108023 added to mysqli-stmt.prepare | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186780@lists.php.net to get a copy of this message | ||
Note that if you're using a question mark as a placeholder for a string value, you don't
surround it with quotation marks in the MySQL query.
For example, do this:
mysqli_stmt_prepare($stmt, "SELECT * FROM foo WHERE foo.Date > ?");
Do not do this:
mysqli_stmt_prepare($stmt, "SELECT * FROM foo WHERE foo.Date > '?'");
If you put quotation marks around a question mark in the query, then PHP doesn't recognize the
question mark as a placeholder, and then when you try to use mysqli_stmt_bind_param(), it gives an
error to the effect that you have the wrong number of parameters.
The lack of quotation marks around a string placeholder is implicit in the official example on this
page, but it's not explicitly stated in the docs, and I had trouble figuring it out, so figured
it was worth posting.
----
Server IP: 192.41.42.26
Probable Submitter: 67.180.87.190
----
Manual Page -- http://www.php.net/manual/en/mysqli-stmt.prepare.php
Edit -- https://master.php.net/note/edit/108023
Del: integrated -- https://master.php.net/note/delete/108023/integrated
Del: useless -- https://master.php.net/note/delete/108023/useless
Del: bad code -- https://master.php.net/note/delete/108023/bad+code
Del: spam -- https://master.php.net/note/delete/108023/spam
Del: non-english -- https://master.php.net/note/delete/108023/non-english
Del: in docs -- https://master.php.net/note/delete/108023/in+docs
Del: other reasons-- https://master.php.net/note/delete/108023
Reject -- https://master.php.net/note/reject/108023
Search -- https://master.php.net/manage/user-notes.php