78 lines
2.0 KiB
PHP
Executable File
78 lines
2.0 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Schema;
|
|
|
|
use Schema\Db\Table as Table;
|
|
|
|
use Schema\Db\Adapter\PostgresAdapter;
|
|
use Schema\Db\Adapter\MysqlAdapter;
|
|
use Schema\Db\Adapter\SQLiteAdapter;
|
|
use Schema\Db\Adapter\SqlServerAdapter;
|
|
|
|
class Wrapper{
|
|
|
|
private static $_instance;
|
|
|
|
public $_adapter;
|
|
public $_driver;
|
|
|
|
function __construct(){ }
|
|
|
|
//SINGLETON==============================================
|
|
private static function newObj(){
|
|
if (!isset(self::$_instance)) {
|
|
self::$_instance = new Wrapper();
|
|
}
|
|
return self::$_instance;
|
|
}
|
|
|
|
public static function getInstance(){
|
|
if (!isset(self::$_instance)) {
|
|
return self::newObj();
|
|
}
|
|
return self::$_instance;
|
|
}
|
|
//=======================================================
|
|
|
|
public static function set_driver(\PDO $driver){
|
|
$instance = self::getInstance();
|
|
$instance->_driver = $driver;
|
|
|
|
switch ($driver->getAttribute(\PDO::ATTR_DRIVER_NAME)){
|
|
case 'sqlite':
|
|
$instance->_adapter = new SQLiteAdapter();
|
|
$instance-> _adapter->setConnection($driver);
|
|
break;
|
|
case 'pgsql':
|
|
$instance->_adapter = new PostgresAdapter();
|
|
$instance->_adapter->setConnection($driver);
|
|
break;
|
|
case 'mysql':
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
public static function get_table($name){
|
|
$instance = self::getInstance();
|
|
return new Table($name, Array(), $instance->_adapter);
|
|
}
|
|
|
|
public static function begin(){
|
|
$instance = self::getInstance();
|
|
$instance->_adapter->beginTransaction();
|
|
}
|
|
|
|
public static function commit(){
|
|
$instance = self::getInstance();
|
|
$instance->_adapter->commitTransaction();
|
|
}
|
|
|
|
public static function exec($sql){
|
|
$instance = self::getInstance();
|
|
$instance->_driver->exec($sql);
|
|
}
|
|
|
|
} |