-1

我正在编写一个在我的 PostgreSQL 数据库上运行查询的 PHP 代码:

$insert = pg_query($pg_conn, 
"INSERT INTO kullanicilar(id, u_name, u_firstname, u_lastname, register_date, gold, exp, play_times, level)
VALUES($k_id, '$u_name', '$u_firstname', '$u_lastname', 'NOW()', 0, 0, 0, 1);"
);

if ($insert) {
    echo 'Insert succeeded.';
} else {
    echo 'An error occurs when inserting';
}

每次插入消息时都会出现错误。我的代码有什么问题?

-编辑-(详细信息)

我正在使用 Heroku Postgres。我的变量定义是这样的;

$k_id = intval($basic['id']); //int
$u_name = $basic['name']; //string
$u_firstname = $basic['first_name']; //string
$u_lastname = $basic['last_name']; //string

这是我的heroku日志的一部分:

PHP Warning:  pg_pconnect(): Unable to connect to Postg
reSQL server: could not connect to server: Connection refused\n\tIs the server r
unning on host "-----.amazonaws.com" and accepting\n\tTCP/
IP connections on port 5432? in /app/www/index.php on line 91, referer: http://a
pps.facebook.com/---/

PHP Warning:  pg_last_error() expects parameter 1 to be
resource, boolean given in /app/www/index.php on line 119, referer: http://apps
.facebook.com/---/

PHP Warning:  pg_num_rows() expects parameter 1 to be r
esource, null given in /app/www/index.php on line 106, referer: http://apps.face
book.com/---/

PHP Warning:  pg_query() expects parameter 1 to be reso
urce, boolean given in /app/www/index.php on line 107, referer: http://apps.face
book.com/---/

PHP Warning:  pg_last_error(): No PostgreSQL link opene
d yet in /app/www/index.php on line 111, referer: http://apps.facebook.com/---/

PHP Warning:  pg_query() expects parameter 1 to be reso
urce, boolean given in /app/www/index.php on line 98, referer: http://apps.faceb
ook.com/---/
4

1 回答 1

1

如果register_date应该是timestamp(带时区),它应该是now()(不带单引号,函数调用)而不是'now()'(带单引号,字符串文字)。

Postgres 发出更详细的错误消息。检查数据库日志。

pgAdmin只是一个图形用户界面。如果它驻留在客户端上,它可能根本无法访问服务器上的日志文件。如果它驻留在同一台机器上,则只需正确配置即可。

Every halfway decently configured Postgres server writes log files. Look in postgresql.conf at the settings described here to find out or configure where.

于 2013-01-08T06:51:39.400 回答