나는 MySQL에서 Postgres로 사이트를 변환하고 있으며 정말 이상한 버그가 있습니다. 이 코드는 RDBMS를 전환하기 전에 그대로 작동합니다. 다음 루프에서 :pg_query()가 루프에서 쿼리를 실행하지 않는 것 같습니다
foreach ($records as $record) {
print "<li> <a href = 'article.php?doc={$record['docid']}'> {$record['title']} </a> by ";
// Get list of authors and priorities
$authors = queryDB($link, "SELECT userid FROM $authTable WHERE docid='{$record['docid']}' AND role='author' ORDER BY priority");
// Print small version of author list
printAuthors($authors, false);
// Print (prettily) the status
print ' (' . nameStatus($record['status']) . ") </li>\n";
}
첫 번째 쿼리는 문제가 없습니다. 후속 호출이 작동하지 않습니다 (pg_query가 도우미 함수에서 false를 반환하므로 죽습니다).
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 into an array
while($line = pg_fetch_assoc($result)) {
$retarray[] = $line;
}
pg_free_result($result);
return $retarray;
}
진짜로 이상한 부분 : queryDB의 코드는 다음과 내가 (PHP의 함께 연결 동일한 사용자로) 쿼리를 복사 psql
그것을 실행하면 모든 것이 잘 실행됩니다. 또는 함수 호출 대신 쿼리 문자열을 루프에 복사하면 올바른 결과를 얻습니다. 그러면이 래퍼가 버그를 일으키는 방법은 무엇입니까?
감사합니다.
'pg_last_error()'를 실행하고 출력을 알려주십시오. – Woot4Moo
이상하게도'pg_set_error_verbosity ($ link, PGSQL_ERRORS_VERBOSE);와 함께'pg_last_error()'의 출력이 없습니다. 래퍼가 이미'pg_last_error'를 호출하고 있습니다; 출력을 보려면 http://peano.colorado.edu/libermath/repositorium/?field=8을보십시오 (2010-12-02T1601 MST 기준). –
왜 pg_fetch_all()을 사용하지 않습니까? while 루프가 필요 없습니다. –