这是我的功能:
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);
//*/
}
当我以最佳方式执行此操作时(未注释掉),我收到 HY093 错误。当我以最底层的方式进行操作时,它完美地工作。
在我的数据库中:
- 3dprinting_id 是一个整数,不能为空
- 机器是varchar(30),可以是null
- 开始时间为日期,不能为空
- Grams是一个int,可以为null
- color 为 varchar(30),可以为 null
最佳答案
就像变量一样,绑定(bind)也是区分大小写的。
你的值中有这个 ( :3dprinting_id
然后你在做
bindParam(":3dPrinting_id"
他们需要在字母大小写上匹配。
bindParam(":3dprinting_id"
关于php - 为什么我会收到 HY093 错误 [PDO],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29679595/