你可以帮我解决下面的问题吗?
php code://
$countdate='2017-01-03';
$countsql='SELECT rucid,"databaseType","countLoggedOn","prodCount","nprodCount","countType" FROM "ru_countLog" WHERE "countLoggedOn"=$countdate';
- >它给出了语法错误
语法错误或附近" $"第1行:...... untType" FROM" ru_countLog" 在哪里" countLoggedOn" = $ countdate
答案 0 :(得分:1)
从查询中删除内部双引号:
$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
是您的数据库连接
答案 1 :(得分:0)
也许你应该尝试这样
$countdate='2017-01-03';
$countsql='SELECT rucid,"databaseType","countLoggedOn","prodCount","nprodCount","countType" FROM "ru_countLog" WHERE "countLoggedOn"='.$countdate;
希望这个帮助