我正在尝试使用准备好的语句来使用 PHP 和 Postgres 进行简单的插入。到目前为止,我已经这样做了:
<?php
$conn_string = "host=localhost port=5432"; // plus us/pw
$dbconn = pg_connect($conn_string);
$table = 'business_primary_category';
$column = 'primary_category';
$tag = 'restuarant';
// Prepare a query for execution
$result = pg_prepare($dbconn, "my_query", 'SELECT * FROM $table WHERE $column = $1');
// Execute the prepared query. Note that it is not necessary to escape
// the string "Joe's Widgets" in any way
$result = pg_execute($dbconn, "my_query", array("$tag"));
?>
我基本上是从 php.net 上的页面中获取的,并且无法弄清楚我做错了什么。我是否需要安装一个库才能使用它或其他东西。谢谢!
这些是我得到的错误:
Warning: pg_prepare() [function.pg-prepare]: Query failed: ERROR: syntax error at or near "$" at character 15 in /home/url **......** pdo.php on line 11
Warning: pg_execute() [function.pg-execute]: Query failed: ERROR: prepared statement "my_query" does not exist in /home/url **......** pdo.php on line 15
Warning: pg_execute() [function.pg-execute]: Query failed: ERROR: prepared statement "my_query" does not exist in /home/url **......** pdo.php on line 18