gpt4 book ai didi

PHP PDO 语法错误或访问冲突 : 1064 on insert

转载 作者:IT王子 更新时间:2023-10-28 23:53:35 27 4
gpt4 key购买 nike

我有一个表名板,我正在尝试使用当前代码插入数据

function createBoard( $name, $desc  ) {
try {
$sth = $this->getLink()->prepare( "INSERT INTO boards(id,memberid,name,desc,datecreated,isactive)
VALUES(?,?,?,?,?,?)" );

$uuid = $this->uuid();
$memberid = 1;
$date = Utils::getDate();
$isactive = 1;

$sth->bindParam( 1, $uuid );
$sth->bindParam( 2, $memberid );
$sth->bindParam( 3, $name );
$sth->bindParam( 4, $desc );
$sth->bindParam( 5, $date );
$sth->bindParam( 6, $isactive );
return $sth->execute();
} catch( PDOException $e ) {
/*
* save the error to the error log defined as @ERROR_LOG
*/
file_put_contents( ERROR_LOG, ( "\n" . Utils::getDate() . " : " . $e->getMessage() ), FILE_APPEND);
die( "FATAL ERROR...Please check the error log." );
}
}

但是,每次我收到此错误“2012-05-11 14:40:50:SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;请查看手册与您的 MySQL 服务器版本相对应,以便在 'desc,datecreated,isactive) 附近使用正确的语法 VALUES('d5989c7e-9b98-11e1-88cd-0026b936528c','1' at line 1"

我已经使用 bindValue() 尝试了相同的函数,只是将具有直接值的数组放入 $sth->execute() 函数中,但我总是收到同样的错误。也许外人可以发现我遗漏或做错了什么?

最佳答案

用反引号(`) 封装您的字段名称,desc 是保留字。

$sth = $this->getLink()->prepare( "INSERT INTO `boards` (`id`,`memberid`,`name`,`desc`,`datecreated`,`isactive`) 
VALUES(?,?,?,?,?,?)" );

关于PHP PDO 语法错误或访问冲突 : 1064 on insert,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10556941/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com