php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35824 prepared quries returning 0 rows with variable in multiple places
Submitted: 2005-12-28 01:39 UTC Modified: 2005-12-28 08:28 UTC
From: xing at mac dot com Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.1.2RC1 OS: centos 4.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: xing at mac dot com
New email:
PHP Version: OS:

 

 [2005-12-28 01:39 UTC] xing at mac dot com
Description:
------------
Mysql version 4.1.15

use mysql_pdo with attribute enabled to have it throw exception on all errors:







Reproduce code:
---------------
$st = $db->prepare("select * from test where c = 2 AND (a = :a OR b =
:a)");

$st->execute(array(":a" => 2));

Expected result:
----------------
Rows matching where a == 2 or b == 2 OR an exception if pdo doesn't support having the same variable appear more than once in a prepared query.

Actual result:
--------------
0 row result regardless of what's in the database. No error or
exceptions from pdo. Everything points to successful query when nothing has been executed.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-28 08:28 UTC] xing at mac dot com
Turns out it's because I did not set the error attribute correctly. Apparently you cannot set it via the construct method.

new PDO("mysql:host=1.1.1.1;unix_socket=/tmp/my.sock;dbname=testdb",
$USER,
$PASS,
array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION			);

the above does not work...to set the error mode attribute..had to use the below after pdo connection is made.

setAttribute (PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 06:01:29 2024 UTC