我正在编写一个在我的 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/---/