|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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);
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 14:00:01 2025 UTC |
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']); }