#38643 [Opn->Bgs]: PDO/mysql: wrong results in prepared statement when using parameter twice
| From: | iliaa@php.net | Date: | Wed, 30 Aug 2006 16:19:00 +0000 |
| Subject: | #38643 [Opn->Bgs]: PDO/mysql: wrong results in prepared statement when using parameter twice | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-101544@lists.php.net to get a copy of this message | ||
ID: 38643
Updated by: iliaa@php.net
Reported By: chris dot vigelius at gmx dot net
-Status: Open
+Status: Bogus
Bug Type: PDO related
Operating System: Linux
PHP Version: 5.1.5
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
This is a limitation of the MySQL prepared statement syntax
which does not support re-usable identifiers. To make your
query work you need to set PDO::ATTR_EMULATE_PREPARES to true.
Previous Comments:
------------------------------------------------------------------------
[2006-08-30 11:31:40] chris dot vigelius at gmx dot net
Expected result:
----------------
array(0) { } array(0) { }
Actual result:
--------------
array(2) { [0]=> object(stdClass)#4 (2) { ["name"]=>
string(5) "fritz" ["email"]=>
string(16) "fritz@server.com" } [1]=> object(stdClass)#5
(2) { ["name"]=> string(4) "otto" ["email"]=>
string(15) "otto@server.com" } } array(0) { }
------------------------------------------------------------------------
[2006-08-30 11:27:56] chris dot vigelius at gmx dot net
// prepare the database
$dbh = new
PDO('mysql:host=localhost;dbname=test', 'test', 'test');
$dbh->exec("DROP TABLE IF EXISTS user");
$dbh->exec("CREATE TABLE user ( name VARCHAR(32), email
VARCHAR(32), PRIMARY KEY (name) );");
$dbh->exec("INSERT INTO user VALUES
('fritz', 'fritz@server.com')");
$dbh->exec("INSERT INTO user VALUES
('otto', 'otto@server.com')");
// this will return 2 rows where 0 are expected
$stmt = $dbh->prepare("SELECT * FROM user WHERE name=:user
OR email=:user");
$stmt->execute(array(':user' => 'franz'));
$rows = $stmt->fetchAll(PDO::FETCH_OBJ);
var_dump($rows);
// this workaround will return 0 rows as expected
$stmt = $dbh->prepare("SELECT * FROM user WHERE name=:user1
OR email=:user2");
$stmt->execute(array(':user1' => 'franz', ':user2'
=> 'franz'));
$rows = $stmt->fetchAll(PDO::FETCH_OBJ);
var_dump($rows);
------------------------------------------------------------------------
[2006-08-30 11:12:34] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.
A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc. If the script requires a
database to demonstrate the issue, please make sure it creates
all necessary tables, stored procedures etc.
Please avoid embedding huge scripts into the report.
------------------------------------------------------------------------
[2006-08-30 11:11:15] chris dot vigelius at gmx dot net
the current snapshot does NOT solve the problem - there are
still all rows returned.
------------------------------------------------------------------------
[2006-08-29 20:45:43] tony2001@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php5.2-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5.2-win32-latest.zip
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/38643
--
Edit this bug report at http://bugs.php.net/?id=38643&edit=1