Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I receiving HY093 error [PDO]

Tags:

php

mysql

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
like image 865
cdm014 Avatar asked Apr 16 '15 15:04

cdm014


1 Answers

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"
like image 91
Funk Forty Niner Avatar answered Sep 29 '22 01:09

Funk Forty Niner