Does anyone have a code for manual transactions? I've searched and searched, but I always find the same for it (this is what I have):
try
{
$bd = new PDO('mysql:host=localhost;charset=utf8', $argv[2], $argv[3],
array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
);
}
catch (PDOException $e)
{
throw new Exception('conexión con MySQL.', 2);
}
try
{
$archivos = array('tablas', 'procedimientoss', 'triggers');
$bd->beginTransaction();
$bd->exec('CREATE DATABASE IF NOT EXISTS ' . $argv[1] . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_spanish_ci');
$bd->exec('USE ' . $argv[1]);
foreach ($archivos as $archivo)
{
$bd->exec(file_get_contents('../bd/' . $archivo . '.sql'));
}
$bd->commit();
}
catch (PDOException $e)
{
$bd->rollBack();
throw new Exception('instalacion de la base de datos', 2);
}
But beginTransaction()
doesn't disable MySQL autocommit: even setting array(PDO::ATTR_AUTOCOMMIT => false (or 0))
. Any help?