Example #1
0
 public static function init()
 {
     if (ENVIRONMENT != 'production') {
         require_once APP_DIR . 'config/' . ENVIRONMENT . '/db.php';
     } else {
         require_once APP_DIR . 'config/db.php';
     }
     self::$config = $config;
     self::$pdo = new PDO('mysql:host=' . self::$config['db_host'] . ';dbname=' . self::$config['db_name'] . '', self::$config['db_username'], self::$config['db_password']);
     self::$pdo->exec('SET NAMES `' . self::$config['db_charset'] . '`');
     self::$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
     return self::$pdo;
 }
Example #2
0
 function __construct($tableName)
 {
     $defaultConfig = array('db' => null, 'cache' => null, 'path' => './model');
     self::$config = array_merge($defaultConfig, self::$config);
     $file = self::$config['path'] . "/{$tableName}.php";
     $class = 'modelAbsract';
     if (file_exists($file)) {
         require $file;
         $class = "{$tableName}Model";
     }
     $this->table = '{{' . $tableName . '}}';
     $this->model = new $class(self::$config['db'], self::$config['cache'], $tableName);
 }