php.net |  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
Votes:1
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
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: eser at turkishqf dot org
New email:
PHP Version: OS:

 

 [2005-07-16 14:00 UTC] eser at turkishqf dot org
Description:
------------
"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');
	print_r($tQuery);
}

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



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-16 14:21 UTC] helly@php.net
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.

example:
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');
	exit($x);
	echo $system->strings->format('<td><a href="http://{0}.turkishqf.org/"{1}>{2}</a></td>', $tRow['alias'], (($pRequestDomain == $tRow['alias']) ? ' class="act"' : ''), $pStorage['s' . $tRow['fieldidx']]['name']);
}
 [2005-07-16 14:35 UTC] helly@php.net
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] helly@php.net
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

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] wez@php.net
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-2020 The PHP Group
All rights reserved.
Last updated: Fri Nov 27 11:01:24 2020 UTC