Ok. That makes sense now that you say it. I apparently have built the transaction all wrong. I added a = NULL before COMMITing and all three of my updates and inserts execute without stopping.
So, that leads me to my next question. How do you create the transaction if I'm using the class below to handle the connection to the database?
class PDODB
{
private static $instance = null;
public static function get()
{
if(self::$instance == null)
{
try
{
self::$instance = new PDO('mysql:host=localhost;dbname=theDB', 'root', 'root');
}
catch(PDOException $e)
{
// Handle this properly
throw new Exception('DATABASE ERROR: ' . $e->getMessage());
}
}
return self::$instance;
}
}
This is how my queries look more or less without the need of a transaction.
$sth = PDODB::get()->prepare("INSERT INTO table (field1, field2, field3, field4)VALUES (?, ?, ?, ?)");
$params = array($var, $var, $var, $var);
$sth->execute($params);
This is how I thought I should handle the queries with a transaction. Keeping in mind there would actually be three or four similar queries below.
try {
$pdo = PDODB::get();
$pdo->beginTransaction();
$sth = $pdo->prepare("INSERT INTO table (field1, field2, field3, field4)VALUES (?, ?, ?, ?)");
$params = array($var, $var, $var, $var);
$sth->execute($params);
$pdo->commit();
}
catch(PDOException $e) {
$pdo->rollBack();
throw new Exception('DATABASE ERROR: ' . $e->getMessage());
}