PDOStatement::bindParam() not setting AI value from MySQL insert?
- by Alan
I have a simple insert statement using PDO php class.
$statement = $db->prepare('INSERT INTO demographics (id,location_id,male,ethnicity_id,birthyear) VALUES (:id,:location_id,:male,:ethnicity_id,:birthyear)');
$statement->bindParam(':id',$demo->id,PDO::PARAM_INT,4);
$statement->bindParam(':location_id', $demo->locationid,PDO::PARAM_INT);
$statement->bindParam(':male',$demo->male,PDO::PARAM_BOOL);
$statement->bindParam(':ethnicity_id',$demo->ethnicityid,PDO::PARAM_INT);
$statement->bindParam(':birthyear',$demo->birthyear,PDO::PARAM_INT);
$statement->execute();
print_r($demo);
Even though the statement executes correctly (row is correctly written), $demo-id is null.
Any thoughts?