2015-04-16 21 views
5

qui è la mia funzione:Perché ricevo HY093 errore [DOP]

function create($printing_id,$Machine,$Started,$Grams,$color) { 
     //* 
     $this->sql = "insert into `".$this->tableName."` (`3dprinting_id`,`Machine`,`Started`,`Grams`,`color`) values (:3dprinting_id , :Machine, :Started , :Grams , :color)"; 
     $this->stmt = $this->dbh->prepare($this->sql); 
     $this->stmt->bindParam(":3dPrinting_id",$printing_id,PDO::PARAM_INT); 
     $this->stmt->bindParam(":Machine",$Machine,PDO::PARAM_STR); 
     $this->stmt->bindParam(":Started",$Started,PDO::PARAM_STR); 
     $this->stmt->bindParam(":Grams",$Grams,PDO::PARAM_INT); 
     $this->stmt->bindParam(":color",$color,PDO::PARAM_STR); 
     $this->params = array(); 
     $this->params[":3dPrinting_id"] = $printing_id; 
     $this->params[":Machine"] = $Machine; 
     $this->params[":Started"] = $Started; 
     $this->params[":Grams"] = $Grams; 
     $this->params[":color"] = $color; 
     return $this->stmt->execute(); 
     //*/ 
     /* 
     $this->sql = "insert into `".$this->tableName."` (`3dprinting_id`,`Machine`,`Started`,`Grams`,`color`) values ($printing_id,'$Machine','$Started',$Grams,'$color')"; 
     return $this->dbh->exec($this->sql); 
     //*/ 
    } 

Quando faccio nel modo superiore (non commentata) ottengo un errore HY093. Quando lo faccio in fondo funziona perfettamente.

nel mio database:

  • 3dprinting_id è un int, non può essere nullo
  • Machine è varchar (30), può essere nullo
  • Iniziare è datetime, non può essere nullo
  • grammi è un int, potrà essere nullo
  • colore è varchar (30), può essere nullo

risposta

8

Proprio come le variabili, i bind sono case-sensitive.

avete questo nei vostri valori (:3dprinting_id

e poi si sta facendo

bindParam(":3dPrinting_id" 

Hanno bisogno di abbinare nella lettera e minuscole.

bindParam(":3dprinting_id" 
+0

Accettarlo appena possibile. Ho persino visto questo tipo di problema menzionato in altre domande e non riuscivo a capirlo. – cdm014

+0

@ cdm014 Ho già fatto lo stesso errore e sono sicuro che ci siano stati anche molti altri, * evviva * –

Problemi correlati