My try:
1st File (connopen.php)
<?php
try {
$db = new PDO(DB_DSN, DBUSER, DB_PASSWORD);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
} catch (PDOException $e) {
die('Cannot connecto to database!');
}
try {
$db->beginTransaction();
Other Files (file1.php, file2.php ...)
<?php
include('connopen.php');
...some code using SQL(SELECT, INSERT INTO, UPDATE, DELETE ....)
include('connclose.php');
?>
Last File (connclose.php)
<?php
$db->commit();
} catch (PDOException $e) {
$db->rollBack();
..some code to log errors
}
$db = null;
?>
This as is, throws an Error (Parse error: syntax error, unexpected $end in /connopen.php on line 11) because I start try { on connopen.php and I closed on connclose.php
If there is another way to do something like that to prevent double-triple coding... of connopen and connclose source code will appreciate. thanks