Erreur:SQLSTATE [42000]:语法错误或访问冲突:1064您的SQL语法中有错误;

时间:2011-03-18 14:15:10

标签: php

当我尝试执行更新语句时,我收到以下错误:

Erreur : 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 'Issy-les-Moulineaux ' where ssiphone_idstation=46' at line 1

我的更新声明是:

$bdd->exec("update ssiphone_stationdeservice set $cle='$element' where ssiphone_idstation=$id");

这是一个PHP代码,THX提前为您提供帮助:)

$ cle和$ element在数组中,我的代码是:

 foreach($table1 as $cle => $element)
   {
   $bdd->exec("update ssiphone_stationdeservice set $cle='$element' where ssiphone_idstation=$id");
   }

现在table1是一个数组,其中包含我的表的列名及其值:

$table1=array();
   $table1['ssiphone_etatstation']=$etat;
   $table1['ssiphone_commerce']=$commerce;
   $table1['ssiphone_stationdelavage']=$lavage;
   $table1['ssiphone_typescarburants']=$lescarburants;
   $table1['ssiphone_joursdelasemaine']=$jourssemaines;
   $table1['ssiphone_horaires ']=$this->horaires;
   $table1['ssiphone_telephone ']=$telephone;
   $table1['ssiphone_sensdecirculation ']=$this->sensDeCirculation;
   $table1['ssiphone_adresse ']=$this->adresse;
   $table1['ssiphone_ville']=$this->ville;
   $table1['ssiphone_departement']=$this->departement;
   $table1['ssiphone_nomstation ']=$this->nomStation;

1 个答案:

答案 0 :(得分:1)

很可能未设置$ cle变量,使查询看起来像:

... set ='Issy-les-moulineaux ' where ...

评论后续:

将代码更改为如下所示,然后:

$query = "update ssiphone_stationdeservice set $cle='$element' where ssiphone_idstation=$id";
$result = $bdd->exec($query);
if ($result === FALSE) {
    print_r($bdd->errorInfo());
    die("Query: " . $query);
}

这样,您可以在可以检查的变量中拥有完整的查询字符串(例如,通过回显)。显然查询有问题 - 但是mysql错误字符串不显示整个查询,所以你必须采取措施来捕获它。