note 76357 added to function.PDOStatement-bindParam
| From: | jeffwa+php at gmail dot com | Date: | Wed, 11 Jul 2007 20:49:33 +0000 |
| Subject: | note 76357 added to function.PDOStatement-bindParam | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128392@lists.php.net to get a copy of this message | ||
Took me forever to find this elsewhere in the notes in the manual, so I'd thought I'd put
this tidbit here to help others in the future.
When using a LIKE search in MySQL along with a prepared statement, the *value* must have the
appropriate parentheses attached before the bindParam() statement as such:
<?php
$dbc = $GLOBALS['dbc'];
$sql = "SELECT * FROM
tbl_name WHERE tbl_col LIKE ?";
$stmt = $dbc->prepare($sql);
$value = "%{$value}%";
$stmt->bindParam($i, $value, PDO::PARAM_STR);
?>
Trying to use
<?php
$stmt->bindParam($i, "%{$value}%", PDO::PARAM_STR);
?>
will fail.
----
Server IP: 69.147.83.197
Probable Submitter: 208.108.4.76
----
Manual Page -- http://www.php.net/manual/en/function.PDOStatement-bindParam.php
Edit -- https://master.php.net/note/edit/76357
Del: integrated -- https://master.php.net/note/delete/76357/integrated
Del: useless -- https://master.php.net/note/delete/76357/useless
Del: bad code -- https://master.php.net/note/delete/76357/bad+code
Del: spam -- https://master.php.net/note/delete/76357/spam
Del: non-english -- https://master.php.net/note/delete/76357/non-english
Del: in docs -- https://master.php.net/note/delete/76357/in+docs
Del: other reasons-- https://master.php.net/note/delete/76357
Reject -- https://master.php.net/note/reject/76357
Search -- https://master.php.net/manage/user-notes.php