note 120138 added to mysqli-stmt.bind-param
| From: | Matze | Date: | Thu, 10 Nov 2016 07:57:38 +0000 |
| Subject: | note 120138 added to mysqli-stmt.bind-param | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-207059@lists.php.net to get a copy of this message | ||
Hey Folks,
just wanted to mention that parameters can only be used for input data, NOT for Table, Columns or
Database names.
That gave me a headache yesterday!
So this code will not work:
$searchtype = "Title";
$searchterm = "The Fellowship of the Ring: The Lord of the Rings";
$query =
"SELECT ISBN, Author, Title, Price
FROM books
WHERE ? = ?";
$mySql_stmt = $db->prepare($query);
$mySql_stmt->bind_param("ss" , $searchtype, $searchterm);
$mySql_stmt->execute();
In contrast, you will have to include the searchtype in ther query directly like this:
$searchtype = "Title";
$searchterm = "The Fellowship of the Ring: The Lord of the Rings";
$query =
"SELECT ISBN, Author, Title, Price
FROM books
WHERE $searchtype = ?";
$mySql_stmt = $db->prepare($query);
$mySql_stmt->bind_param("s", $searchterm);
$mySql_stmt->execute();
Hope that helps someone to have a peaceful nights sleep :)
----
Server IP: 72.52.91.14
Probable Submitter: 2a02:908:e840:a0:249f:1f92:7886:4cb2
----
Manual Page -- http://php.net/manual/en/mysqli-stmt.bind-param.php
Edit -- https://master.php.net/note/edit/120138
Del: integrated -- https://master.php.net/note/delete/120138/integrated
Del: useless -- https://master.php.net/note/delete/120138/useless
Del: bad code -- https://master.php.net/note/delete/120138/bad+code
Del: spam -- https://master.php.net/note/delete/120138/spam
Del: non-english -- https://master.php.net/note/delete/120138/non-english
Del: in docs -- https://master.php.net/note/delete/120138/in+docs
Del: other reasons-- https://master.php.net/note/delete/120138
Reject -- https://master.php.net/note/reject/120138
Search -- https://master.php.net/manage/user-notes.php