note 76966 added to function.PDOStatement-execute
| From: | simon dot lehmann at gmx dot de | Date: | Wed, 08 Aug 2007 10:17:05 +0000 |
| Subject: | note 76966 added to function.PDOStatement-execute | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129287@lists.php.net to get a copy of this message | ||
It seems, that the quoting behaviour has changed somehow between versions, as my current project was
running fine on one setup, but throwing errors on another (both setups are very similar).
Setup 1: Ubuntu 6.10, PHP 5.1.6, MySQL 5.0.24a
Setup 2: Ubuntu 7.04, PHP 5.2.1, MySQL 5.0.38
The code fragment which caused problems (shortened):
<?php
$stmt = $pdo->prepare("SELECT col1, col2, col3 FROM tablename WHERE col4=? LIMIT ?");
$stmt->execute(array('Foo', 1));
?>
On the first Setup this executes without any problems, on the second setup it generates an Error:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check
the manual that corresponds to your MySQL server version for the right syntax to use near
''1'' at line 1
The problem is, that $stmt->execute() quotes the number passed to the second placeholder
(resulting in: ... LIMIT '1'), which is not allowed in MySQL (tested on both setups).
To prevent this, you have to use bindParam() or bindValue() and specify a data type.
----
Server IP: 217.13.201.10
Probable Submitter: 217.7.212.94
----
Manual Page -- http://www.php.net/manual/en/function.PDOStatement-execute.php
Edit -- https://master.php.net/note/edit/76966
Del: integrated -- https://master.php.net/note/delete/76966/integrated
Del: useless -- https://master.php.net/note/delete/76966/useless
Del: bad code -- https://master.php.net/note/delete/76966/bad+code
Del: spam -- https://master.php.net/note/delete/76966/spam
Del: non-english -- https://master.php.net/note/delete/76966/non-english
Del: in docs -- https://master.php.net/note/delete/76966/in+docs
Del: other reasons-- https://master.php.net/note/delete/76966
Reject -- https://master.php.net/note/reject/76966
Search -- https://master.php.net/manage/user-notes.php