我正在使用mysql,我有一个表,他的名字是“概念关系”,我想插入其中
for ($i = 0; $i < count($sources); $i++) {
$sourceID = $this->getConcpeptID($sources[$i]);
$desID = $this->getConcpeptID($distinations[$i]);
$query2 = "INSERT INTO concept-relation (relationID, firstConceptID, secondConceptID)
VALUES (:rID, :sID, :dID)";
$sth = $this->db->prepare($query2);
$sth->execute(array(
':rID' => $relationID,
':sID' => $sourceID,
'dID' => $desID
));
我收到此语法错误消息
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 '-relation (relationID, firstConceptID, secondConceptID) VALUES (' at line 1' in C:\xampp\htdocs\Mar7ba\models\ontology_model.PHP:86 Stack trace: #0 C:\xampp\htdocs\Mar7ba\models\ontology_model.PHP(86): PDOStatement->execute(Array) #1 C:\xampp\htdocs\Mar7ba\controlers\Ontology.PHP(69): Ontology_Model->addRelation('jklljkljk', Array, Array) #2 C:\xampp\htdocs\Mar7ba\libs\Bookstrap.PHP(42): Ontology->relationAdd() #3 C:\xampp\htdocs\Mar7ba\index.PHP(13): Bootstrap->__construct() #4 {main} thrown in C:\xampp\htdocs\Mar7ba\models\ontology_model.PHP on line 86
#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 '"-".relation (relationID, firstConceptID, secondConceptID) VALU' at line 1
问题是因为表的名称在ti中有破折号,看看MysqL如何理解查询
INSERT INTO concept - relation(
relationID,
firstConceptID,
secondConceptID
)
VALUES ( 3, 3, 3 )
它理解概念,只做“ – 关系”,
请帮忙
但不改变我的表名:)
解决方法:
用反引号括起标识符会使保留字/字符成为MysqL中的有效标识符.
所以你应该使用
`concept-relation`