Esempio n. 1
0
File: db.php Progetto: hitzheng/ares
 public function run()
 {
     try {
         $db = Comm_Db::getInstance('test');
         // $sql = "CREATE TABLE if not exists `test` (`col1` int(11) NOT NULL,`col2` varchar(64) NOT NULL, PRIMARY KEY (`col1`)) ENGINE=InnoDB DEFAULT CHARSET=utf8";
         // $ret = $db->exec($sql);
         // var_dump('create table', $ret);
         // for ($i = 0; $i < 5; $i++)
         // {
         //     $sql = "insert into test (col1, col2) values (?,?)";
         //     $db->exec($sql, array($i, "val{$i}"));
         // }
         // var_dump('insert', $i);
         // $db->beginTransaction();
         // $i = 300;
         // $sql = "insert into test (col1, col2) values(?, ?)";
         // $ret = $db->exec($sql, array($i, "val{$i}"));
         // var_dump('traction insert', $ret);
         $i = 2;
         $sql = "select * from test where col1=?";
         $ret = $db->query($sql, array($i));
         var_dump('transaction select', $ret);
         // $db->commit();
         // $sql = "select * from test where col1=?";
         // $ret = $db->query($sql, array($i));
         // var_dump('transaction after rollBack select', $ret);
     } catch (Exception $e) {
         print_r($e);
     }
     var_dump($db);
 }
Esempio n. 2
0
 /**
  * 单例的构造回调,用于初始化
  * @return [type] [description]
  */
 public function onConstruct()
 {
     if (is_null($this->cacheEnable)) {
         $this->cacheEnable = Comm_Config::get('cache.enable', true);
     }
     if (is_null($this->cacheEngine)) {
         $this->cacheEngine = Comm_Config::get('cache.engine', 'redis');
     }
     if (!is_null($this->cachePool)) {
         $this->cache = Comm_Cache::getInstance($this->cachePool, $this->cacheEngine);
     }
     if (!is_null($this->dbPool)) {
         $this->db = Comm_Db::getInstance($this->dbPool);
     }
 }