|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33724 "PDO" object doesn't run in functions.
Submitted: 2005-07-16 14:00 UTC Modified: 2005-09-20 21:56 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: eser at turkishqf dot org Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.1.0b2 OS: freebsd 4.7
Private report: No CVE-ID: None
 [2005-07-16 14:00 UTC] eser at turkishqf dot org
"PDO" object doesn't run in functions.

Reproduce code:
$qDB = new PDO ...

function addToStorage($uId) { // doesn't work
	global $qDB;

	$tQuery = $qDB->prepare('SELECT * FROM `articles` WHERE `idx`=:idx');

// works
$tQuery = $qDB->prepare('SELECT * FROM `articles` WHERE `idx`=:idx');


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-16 14:21 UTC]
If this is mysql then please update php and show all errors and warnings.
 [2005-07-16 14:26 UTC] eser at turkishqf dot org
pardon me, there is no problem while PDO methods running in functions. but i can't execute recursive queries with same PDO object; php triggers "Invalid argument supplied for foreach" error.

foreach ($qDB->query('SELECT NOW() AS z') as $row) {
  foreach ($qDB->query('SELECT NOW() AS x') as $subrow) { // Invalid argument supplied for foreach()
    echo $subrow['x'];

my code:
foreach ($qDB->query('SELECT entities.alias, entities.fieldidx FROM entities WHERE entities.fieldtype=\'s\' AND (entities.parenttype=\'s\' AND entities.parentidx=\'0\')', PDO_FETCH_ASSOC) as $tRow) {
	// addToStorage('s' . $tRow['fieldidx']);
	$x = $qDB->prepare('SELECT * FROM articles');
	echo $system->strings->format('<td><a href="http://{0}"{1}>{2}</a></td>', $tRow['alias'], (($pRequestDomain == $tRow['alias']) ? ' class="act"' : ''), $pStorage['s' . $tRow['fieldidx']]['name']);
 [2005-07-16 14:35 UTC]
to repeat the Q: ARE YOU USING MYSQL?
 [2005-07-16 14:37 UTC] eser at turkishqf dot org
yes, mysql-max-4.1.12 on freebsd 4.7
 [2005-07-16 14:43 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

ATM parallel queries are not available using mysql. Wait for someone to write a decent pdo_mysql driver, use a decent rdbms like postgres or use fetchall().
 [2005-07-16 16:14 UTC]
FYI, you should use fetchAll().
The PDO MYSQL driver *is* decent, and what you're trying to do is not supported by most major databases.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 06:01:34 2024 UTC