我没有制作这些列名,因为它们是通过上传 CSV 文件创建的 作为“COL 1”“COL 2”
connect();
global $db;
$sql = $db->prepare("UPDATE table1 SET 'COL 1'=:c1 where table1_id=:id");
$sql->bindParam(':id',$arry['id'],PDO::PARAM_STR, 12);
$sql->bindParam(':c1',$arry['t1'],PDO::PARAM_STR, 12);
try
{
$sql->execute();
}
catch(PDOException $e)
{
echo($e);
}
错误显示是
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 '1='DDEE' where table1_id='5'' at line 1' in C:\wamp\www\excelsheets\functions.php:109 Stack trace: #0 C:\wamp\www\excelsheets\functions.php(109): PDOStatement->execute() #1 C:\wamp\www\excelsheets\save4.php(4): save4_update(Array) #2 {main}
我知道我们不能在准备好的语句中使用 '' 单引号 那么如何表示中间有空格的列呢?
最佳答案
MySQL 中的转义字符是反引号(或反引号)。这是它的外观示例:
UPDATE table1
SET `COL 1` = :c1
where table1_id = :id
关于php - 如何在pdo准备语句中用空格写列名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23230593/