php - pg_query() seems to not execute queries in a loop -
i'm converting site mysql postgres , have weird bug. code worked as-is before switched rdbms. in following loop:
foreach ($records $record) { print "<li> <a href = 'article.php?doc={$record['docid']}'> {$record['title']} </a> "; // list of authors , priorities $authors = querydb($link, "select userid $authtable docid='{$record['docid']}' , role='author' order priority"); // print small version of author list printauthors($authors, false); // print (prettily) status print ' (' . namestatus($record['status']) . ") </li>\n"; } the first query fine. subsequent calls don't work (pg_query returns false in helper function, dies). code querydb following:
function querydb($link, $query) { $result = pg_query($link, $query) or die("could not query db! statement $query failed: " . pg_last_error($link)); // push each result array while( $line = pg_fetch_assoc($result)) { $retarray[] = $line; } pg_free_result($result); return $retarray; } the strange part: when copy query , run psql (as same user php's connecting with) runs fine. or if copy meat of querydb loop in place of function call, correct result. how wrapper causing bugs?
thanks!
i discovered there no error output due having php.ini misconfigured; after turning errors on started getting output, got things like18 not valid postgresql link resource. changing connect code use pg_pconnect() (the persistent version) fixed this. (found idea here.)
thanks took , tried help!
Comments
Post a Comment