Problem with PDO prepared insert
Posted: Sun Nov 21, 2010 7:51 pm
Below is the code I've tried to use to insert data into a table. The code in the comments works. The other code does not. I don't know why. Help.
Code: Select all
/*
$count = $DBH->exec("INSERT INTO assets(asset_name, date_added, short_desc) VALUES ('crappy', NOW(), 'some crappy crap')");
echo $count;
$DBH = null;
*/
$stmt=$DBH->prepare("INSERT INTO assets(asset_name, date_added, short_desc) VALUES (:asset_name, NOW(), :short_desc)");
$stmt->bindParam(':asset_name', $asset_name, PDO_PARAM_STR, 64);
$stmt->bindParam(':short_desc', $short_desc, PDO_PARAM_STR, 64);
$asset_name = 'more crap';
$short_desc = 'some more crap';
$stmt->execute();
$stmt = null;