PHP와 Postgres를 사용하여 간단한 삽입 작업을 수행하기 위해 준비된 문을 사용하려고합니다. 지금까지, 나는이 일을했습니다문자열 보간 된 준비된 문이 구문 오류로 인해 실패합니다.
내가 php.net의 페이지에서 기본적으로 촬영했습니다, 그리고 내가 잘못 한 일을 알아낼 수 없습니다<?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"));
?>
. 그것을 사용하기 위해 라이브러리를 설치해야합니까? 감사! 'SELECT * FROM $table WHERE $column = $1'
에 따옴표를 사용 ... 밖으로 점프
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
변수를 평가하려면 쿼리 주위에 큰 따옴표가 필요할 수 있습니다. –