我的表格如下
CREATE TABLE IF NOT EXISTS BID_1s (
secId varchar(6) NOT NULL UNIQUE,
fhigh float,
flow float,
fopen float,
fclose float,
fdate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(secId)
) ENGINE MEMORY;
和代码是
$param = array(
":table" => $table, // $table = BID_1s
":secId" => $secId, //$secId = 4001
":fhigh" => $high, // $high = 22.65
":flow" => $low, // $low = 22.00
":fopen" => $open, // $open = 22.21
":fclose" => $close, //$close = 22.34
":fdate" => $tempDate, // $tempDate = 2014-12-00 00:00:00
);
$query .= "INSERT INTO :table (`secId`, `fhigh`, `flow`, `fopen`, `fclose`, `fdate`) "
. "VALUES (':secId', :fhigh, :flow, :fopen, :fclose, ':fdate') "
. "ON DUPLICATE KEY UPDATE "
. "fhigh=:fhigh, flow=:flow, fclose=:fclose, fopen=:fopen; \n";
$stmt = $this->dh->prepare($query);
foreach ($param as $param_key => $param_value) {
$stmt->bindParam($param_key, $param_value);
}
if (!$stmt) {
echo "\nPDO::errorInfo():\n";
print_r($this -> dh -> errorInfo());
}
$exec = $stmt->execute();
当我运行程序时显示语法错误:
PHP致命错误:带有消息'SQLSTATE [42000]的未捕获异常'PDOException':语法错误或访问冲突:1064 SQL语法中有错误;查看与您的MySQL服务器版本对应的手册,以便在“2014-12-00 00:00:00”附近使用正确的语法(
secId
,fhigh
,flow
,{ {1}},fopen
,fclose
)VAL'位于/var/www/html/storeSocketData/mysqlDriver.php:53的第1行
如果你注意我的$ tempDate绑定:table并用它替换
这是PHP PDO中的Bug还是我无法在PDO中绑定表名?
如果我不使用bind并在查询中直接赋值,我的查询工作Okey