|
|
|
@ -28,6 +28,9 @@
|
|
|
|
|
* @author Daan Janssens, mentored by Matthew Lagoe
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
$PDOCache = array();
|
|
|
|
|
|
|
|
|
|
class DBLayer {
|
|
|
|
|
|
|
|
|
|
private $PDO;
|
|
|
|
@ -44,8 +47,10 @@ class DBLayer {
|
|
|
|
|
*/
|
|
|
|
|
function __construct($db, $dbn = null)
|
|
|
|
|
{
|
|
|
|
|
if ( $db != "install" ) {
|
|
|
|
|
|
|
|
|
|
global $PDOCache;
|
|
|
|
|
if (isset($PDOCache[$db])) {
|
|
|
|
|
$this->PDO = $PDOCache[$db];
|
|
|
|
|
} else {
|
|
|
|
|
global $cfg;
|
|
|
|
|
$dsn = "mysql:";
|
|
|
|
|
$dsn .= "host=" . $cfg['db'][$db]['host'] . ";";
|
|
|
|
@ -57,19 +62,8 @@ class DBLayer {
|
|
|
|
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
|
|
|
|
|
);
|
|
|
|
|
$this->PDO = new PDO($dsn, $cfg['db'][$db]['user'], $cfg['db'][$db]['pass'], $opt);
|
|
|
|
|
} else {
|
|
|
|
|
global $cfg;
|
|
|
|
|
$dsn = "mysql:";
|
|
|
|
|
$dsn .= "host=" . $cfg['db'][$dbn]['host'] . ";";
|
|
|
|
|
$dsn .= "port=" . $cfg['db'][$dbn]['port'] . ";";
|
|
|
|
|
|
|
|
|
|
$opt = array(
|
|
|
|
|
PDO :: ATTR_ERRMODE => PDO :: ERRMODE_EXCEPTION,
|
|
|
|
|
PDO :: ATTR_DEFAULT_FETCH_MODE => PDO :: FETCH_ASSOC
|
|
|
|
|
);
|
|
|
|
|
$this -> PDO = new PDO( $dsn, $_POST['Username'], $_POST['Password'], $opt );
|
|
|
|
|
$PDOCache[$db] = $this->PDO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -145,8 +139,7 @@ class DBLayer {
|
|
|
|
|
$sth -> execute( $data );
|
|
|
|
|
$this -> PDO -> commit();
|
|
|
|
|
}
|
|
|
|
|
catch( Exception $e )
|
|
|
|
|
{
|
|
|
|
|
catch ( Exception $e ) {
|
|
|
|
|
$this -> PDO -> rollBack();
|
|
|
|
|
throw new Exception( "error selection" );
|
|
|
|
|
return false;
|
|
|
|
|