yiiuser
(Kenp Khalid)
September 25, 2010, 10:57pm
1
Hi everyone,
I’m trying to make a transaction when saving a record. The transaction works fine
when i don’t bind parameters, but as soon i bind parameters the record is not saved !!
This is my code:
$transaction=$connection->beginTransaction();
try
{
$sql="INSERT INTO album (album_id, title_id) VALUES(:album,:title)";
$command=$connection->createCommand($sql);
$command->bindParam(":album", $album_id,PDO::PARAM_INT);
$album_id=$album;
$command->bindParam(":title", $title_id,PDO::PARAM_INT);
$title_id=$title;
$command->execute();
$transaction->commit();
}
catch(Exception $e)
{
$transaction->rollBack();
}
Do you have an idea why the record is not saved when using bind parameters ?
Thanks
mdomba
(Maurizio Domba Cerin)
September 26, 2010, 11:32am
2
First you are binding the variable $album_id, and after that you assign to it the value of variable $album ?
What is the value of $album_id at the time of calling bindParam?
yiiuser
(Kenp Khalid)
September 26, 2010, 7:29pm
3
mdomba:
First you are binding the variable $album_id, and after that you assign to it the value of variable $album ?
What is the value of $album_id at the time of calling bindParam?
The value of $album i call it in a function. But this is not the problem, the problem
is something else and i don’t know where and what. As i said, when i don’t use the transaction it’s works. And as i combine transaction and bind parameters it crash
zaccaria
(Matteo Falsitta)
September 27, 2010, 10:35am
4
Try adding a throw $e after $transaction->rollBack(), so if you have some exception you will see.