1

i fight with DB, trying to insert true and false values to my table with column boolean, but always getting just error:

Invalid parameter number

tested with:

$value = true
$value = "true"
$value = 1

Can somebody please advise me? Thanks

EDIT: full code would looks like:

// adding value to variabile
                    if (empty($row['vin']))
                        $vin = 0;                   
                    else
                        $vin = 1;
//calling insert method
$this->insertToTable($model_code, $typ, $kind, $ts, $vin,  $smr, $ire, $manufacturer_code);

//full insert method:
    public function insertToTable($code, $name, $kind, $ts, $vin, $smr, $ire, $manufacturer_code)
    {                   
        try {                                       
            $con = new PDO( DB_HOST, DB_USER, DB_PASS );            
            $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );            
            $sql = "INSERT INTO r_vehicle_model(code, name, kind, ts, vin, smr, ire, manufacturer_code) VALUES(:code, :name, :kind, :ts, :smr, :ire, :manufacturer_code)";
            $stmt = $con->prepare( $sql );
            $stmt->bindValue( 'code', $code, PDO::PARAM_STR );                
            $stmt->bindValue( 'name', $name, PDO::PARAM_STR );                
            $stmt->bindValue( 'kind', $kind, PDO::PARAM_STR );                
            $stmt->bindValue( 'ts', $ts, PDO::PARAM_STR );                
            $stmt->bindValue( 'vin', $vin, PDO::PARAM_STR );                
            $stmt->bindValue( 'smr', $smr, PDO::PARAM_STR );                
            $stmt->bindValue( 'ire', $ire, PDO::PARAM_STR );                
            $stmt->bindValue( 'manufacturer_code', $manufacturer_code, PDO::PARAM_STR );                
            $stmt->execute();                
            }
        catch( PDOException $e ) {
                echo $e->getMessage();
            }           
    }   

full error:

SQLSTATE[HY093]: Invalid parameter number: :vin

9
  • What is your column type ? Commented Jul 24, 2015 at 11:20
  • my column type is : boolean Commented Jul 24, 2015 at 11:21
  • 1
    Then $value = 1 should work. Can you post your query ? Commented Jul 24, 2015 at 11:23
  • I'm using 'true'/'false' on Laravel Commented Jul 24, 2015 at 11:24
  • 2
    7 placeholders and 8 parameters, that doesn't match.... "Invalid parameter number" Commented Jul 24, 2015 at 11:28

2 Answers 2

1

Forget :vin in insert query. Number of parameter in values is not equal to bindValue

 $sql = "INSERT INTO r_vehicle_model(code, name, kind, ts, vin, smr, ire, manufacturer_code) VALUES(:code, :name, :kind, :ts, ,:vin ,:smr, :ire, :manufacturer_code)";
Sign up to request clarification or add additional context in comments.

Comments

1

You're currently using PDO::PARAM_STR to specify that all the parameters you're passing are strings.

You should make choose the appropriate type for the field, so for a boolean consider using PDO::PARAM_BOOL

http://php.net/manual/en/pdo.constants.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.