PDOStatement::bindParam() not setting AI value from MySQL insert?

Posted by Alan on Stack Overflow See other posts from Stack Overflow or by Alan
Published on 2010-03-23T07:02:17Z Indexed on 2010/03/23 7:03 UTC
Read the original article Hit count: 267

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql