[英]PHP to Postgres, Pass a date variable from a form to PHP to excute a query
[英]Postgres query in php with a date variable
您能在下面的查詢中幫助我嗎?
PHP代碼://
$countdate='2017-01-03';
$countsql='SELECT rucid,"databaseType","countLoggedOn","prodCount","nprodCount","countType" FROM "ru_countLog" WHERE "countLoggedOn"=$countdate';
->出現語法錯誤
“ $”或附近的語法錯誤LINE 1:... untType”來自“ ru_countLog”,而“ countLoggedOn” = $ countdate
從查詢中刪除內部雙引號:
$countsql = "SELECT rucid, databaseType, countLoggedOn,
prodCount, nprodCount, countType
FROM ru_countLog
WHERE countLoggedOn = $countdate";
請注意,此查詢容易受到SQL注入的攻擊。 考慮參數化$countdate
。 使用http://php.net/manual/en/function.pg-query-params.php ,這將成為
$countsql = 'SELECT rucid, databaseType, countLoggedOn,
prodCount, nprodCount, countType
FROM ru_countLog
WHERE countLoggedOn = $1';
$result = pg_query_params($dbconn, $countsql, array($countdate));
$dbconn
是您的數據庫連接
也許你應該這樣嘗試
$countdate='2017-01-03';
$countsql='SELECT rucid,"databaseType","countLoggedOn","prodCount","nprodCount","countType" FROM "ru_countLog" WHERE "countLoggedOn"='.$countdate;
希望這個幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.