我有一个PHP
使用 SELECTSQL
查询的函数。我在这样的查询中使用占位符变量(?)。(此占位符用于 mysql 数据库中的表名):
protected function _fetchPreviousShiftData($table, $report_time)
{
$query = "SELECT * FROM ? WHERE report_date=? and shift=?";
$previousShiftData = $this->_getDbConnection()->fetchAll($query,array($table, date("Y-m-d"), $this->_shiftValue($report_time, 8)));
return $previousShiftData;
}
但是我在 $table 变量中有一个错误,我应该如何使用“?” 对于 $table 变量?错误是这样的:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''adsl_support' WHERE report_date='2013-04-06' and shift='18-2'' at line 1' in C:\php_shared_lib\Zend\Db\Statement\Pdo.php:228