php - 为什么我会收到 HY093 错误 [PDO]

标签 php mysql pdo

这是我的功能:

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/

相关文章:

php - 我无法访问 Laravel 5 中的原始 PDO 实例

mysql - 功能 "SUM does not exist"

php - 根据数组中的另一个 id 仅对多数组中的第一项进行排序(PHP)

php - 在 Windows 中使用 phpexcel 生成 pdf

php - 从文本 block 中提取和删除 URL

mysql - mysql中的大表和请求时间

mysql - 插入MySQL表或更新(如果存在)

php 工具包而不是框架

CentOS 6.5 上的 PHP MSSQL 5.5.8-1?

php - 这是从 mysql 获取单个值的有效查询吗?