简体   繁体   中英

Why am I receiving HY093 error [PDO]

here is my function:

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);
        //*/
    }

When I do it the top way (not commented out) I get an HY093 error. When I do it the bottom way it works perfectly.

In my database:

  • 3dprinting_id is an int, cannot be null
  • Machine is varchar(30), can be null
  • Started is datetime, cannot be null
  • Grams is an int, can be null
  • color is varchar(30), can be null

Just like variables, binds are case-sensitive.

You have this in your values ( :3dprinting_id

and then you're doing

bindParam(":3dPrinting_id"

They need to match in letter-case.

bindParam(":3dprinting_id"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM