#42598 [Opn->Fbk]: Bound parameter values cause no results for fetchAll()
| From: | sixd@php.net | Date: | Sat, 08 Sep 2007 22:36:06 +0000 |
| Subject: | #42598 [Opn->Fbk]: Bound parameter values cause no results for fetchAll() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-117316@lists.php.net to get a copy of this message | ||
ID: 42598
Updated by: sixd@php.net
Reported By: tobias382 at gmail dot com
-Status: Open
+Status: Feedback
Bug Type: PDO related
Operating System: Windows XP SP2
PHP Version: 5.2.4
-Assigned To:
+Assigned To: sixd
New Comment:
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php
If you can provide more information, feel free to add it
to this bug and change the status back to "Open".
Thank you for your interest in PHP.
I can't reproduce this. The script
<?php
$db = new PDO('oci:dbname=ca-tools1/XE', 'hr', 'hrpwd');
$stmt = $db->prepare("select city from locations where country_id =
:c");
$id = "UK";
$stmt->bindParam(":c", $id, PDO::PARAM_STR);
$stmt->execute();
print_r($stmt->fetchAll());
?>
gives the expected:
Array
(
[0] => Array
(
[CITY] => London
[0] => London
)
[1] => Array
(
[CITY] => Oxford
[0] => Oxford
)
[2] => Array
(
[CITY] => Stretford
[0] => Stretford
)
)
Can you examine the data & SQL and identity what does and doesn't work?
Previous Comments:
------------------------------------------------------------------------
[2007-09-08 18:46:03] tobias382 at gmail dot com
Replicating this test within a SQLite environment yields the expected
results, so it's possible that the problem is with the PDO_OCI driver.
------------------------------------------------------------------------
[2007-09-08 17:14:41] tobias382 at gmail dot com
Description:
------------
When using any of the various methods of binding parameter values, a
query produces no results. When including the parameter value directly
in the query string, the query does produce results.
Reproduce code:
---------------
$db = new PDO('oci://localhost/XE', '------', '-----');
$id = 'Wilson';
$sql = 'SELECT C.* FROM BreadCrumbLinks B, BreadCrumbLinks C WHERE
B.Lft BETWEEN C.Lft AND C.Rgt AND B.SiteAreaName = :id ORDER BY C.Lft';
$stmt = $db->prepare($sql);
$stmt->bindValue(':id', $id, PDO::PARAM_STR); // Also tried without
typecasting and without a colon in the parameter name
$stmt->execute(); // also tried with an associative array of parameters
and an enumerated array using ? in place of :id in the query
print_r($stmt->fetchAll());
$sql = 'SELECT C.* FROM BreadCrumbLinks B, BreadCrumbLinks C WHERE
B.Lft BETWEEN C.Lft AND C.Rgt AND B.SiteAreaName = \'' . $id . '\' ORDER
BY C.Lft';
$stmt = $db->prepare($sql);
$stmt->execute();
print_r($stmt->fetchAll());
Expected result:
----------------
Array
(
[0] => Array
(
[SITEAREANAME] => Home
[0] => Home
[SITEAREAURL] => Default.aspx
[1] => Default.aspx
[LFT] => 1
[2] => 1
[RGT] => 24
[3] => 24
)
)
Array
(
[0] => Array
(
[SITEAREANAME] => Home
[0] => Home
[SITEAREAURL] => Default.aspx
[1] => Default.aspx
[LFT] => 1
[2] => 1
[RGT] => 24
[3] => 24
)
)
Actual result:
--------------
Array
(
)
Array
(
[0] => Array
(
[SITEAREANAME] => Home
[0] => Home
[SITEAREAURL] => Default.aspx
[1] => Default.aspx
[LFT] => 1
[2] => 1
[RGT] => 24
[3] => 24
)
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42598&edit=1