PostgreSQL에 관한 새 질문입니다. MacOSX Lion Server 환경에서 Linux 서버에서 호스팅되는 MySQL/PHP 응용 프로그램을 PostgreSQL/PHP로 마이그레이션하려고합니다. Postgres에 대한 나의 첫 경험입니다. 내가 테스트중인 첫 번째 쿼리는 아무 것도 반환하지 않으므로 작동하지 않습니다 (심지어 오류 메시지도 추가하지 않음). 나는 무엇을 잘못 했는가? 나는 PHP 공식 웹 사이트에있는 문서를 포함하여 웹에서 기사를 읽었지만 모든 의견, 개인적인 방법 및 버전과 버전, Postgres 또는 PHP와의 차이점은 매우 혼란스럽게 만들고 결국 필자는 정확하게 작성해야한다는 것을 분명히 이해하지 못한다. 내 쿼리 및 fetch_array. 어떤 제안을 주셔서 감사합니다. 여기 pg_query는 아무 것도 반환하지 않습니다.
는 원래 MySQL의 응용 프로그램에서 내 코드입니다 :// below is the "connexion.php" file
function connexion()
{
[email protected]_connect ("localhost","username","pwd");
if ($link && mysql_select_db ("database"))
return ($link);
return (FALSE);
}
// below is the "index.php" file
require ("connexion.php");
connexion() or exit();
$reqcount = mysql_query ("SELECT * FROM people");
$result = mysql_num_rows($reqcount);
echo "Total : ".$result." people";
mysql_free_result ($reqcount);
mysql_query("set names 'utf8'");
$reqcat = mysql_query ("SELECT catname FROM categories ORDER BY catname");
while ($fieldcat = mysql_fetch_array($reqcat))
{
$name = $fieldcat[catname];
echo $name."<br>";
}
mysql_free_result ($reqcat);
mysql_close();
을 그리고 여기 PostgreSQL의 적응이다 :
// connexion.php
function connexion()
{
$link=pg_connect("host=localhost port=5432 dbname=database user=username password=pwd connect_timeout=5 options='--client_encoding=UTF8'");
return ($link);
}
// index.php
require ("connexion.php");
$reqcount = pg_query ($link,"SELECT * FROM people");
$result = pg_num_rows($reqcount);
echo "Total : ".$result." people";
pg_free_result ($reqcount);
$reqcat = pg_query ($link,"SELECT catname FROM categories ORDER BY catname");
while ($fieldcat = pg_fetch_array($reqcat))
{
$name = $fieldcat[catname];
echo $name."<br>";
}
pg_free_result ($reqcat);
pg_close();
PDO를 사용하는 동안 왜 PDO를 사용하지 않습니까? 그리고'@ '를 사용하여 습관을 버리거나 오류를 억제하십시오. – PeeHaa
시간이 부족하여 최대한 수정하지 않으므로 쿼리 만하는 것이 좋습니다. @에 대한 조언을 주셔서 감사합니다. –