这里有什么问题?我得到了用户表很好。我已确保列名 uid 存在。但是当我尝试从查询中获取 uid 时,什么也没有回来。这很好,因为桌子是空的。但是,我的 INSERT INTO 命令不起作用,因为在 INSERT INTO 之后,我仍然没有返回 uid。使用 Postgres 9.1.5。谢谢!
$query = "SELECT * FROM information_schema.tables WHERE table_name = 'usertable';";
$result = pg_query($dbconn, $query);
if (pg_num_rows($result)) 
{
    echo "Table exists<br>";
    checkForUserRow();
}
else
{
   echo "Error on query, attempting to create table<br>";
   $sql = "CREATE TABLE usertable (uid integer PRIMARY KEY, sign varchar(255));";
   pg_query($dbconn, $sql) or die(pg_errormessage());
   $result = pg_query($dbconn,$query);
   if (pg_num_rows($result)) {
       echo "Table created<br>";
       checkForUserRow();
   }
}
pg_close($conn);
function checkForUserRow()
{
    $query = "SELECT uid FROM usertable WHERE uid = '123'";
    $result = pg_query($dbconn, $query);
if(pg_num_rows($result)) 
{
    echo "User DB row exists<br>";
}
else
{
    echo "User row does not exist - attempt to add user to table<br/>";
    $sql = "INSERT INTO usertable (uid) VALUES('123')";
    pg_query($dbconn, $sql);
    $result = pg_query($dbconn, $query);
    if (pg_num_rows($result)) 
    {
        echo "User successfully added!<br/>";
        }
    else
    {
        echo "User not added :(";
    }
}