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
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)";
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
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.