public function query($query)
 {
     if (PVars::get()->debug) {
         $start_time = microtime(true);
     }
     $q = @mysql_query($query, $this->_dao->cr);
     if (!$q) {
         $e = new PException('MySQL error!', 1000);
         $e->addInfo('Statement: ' . $query);
         $e->addInfo($this->_dao->getErrNo());
         $e->addInfo($this->_dao->getErrMsg());
         throw $e;
     }
     $this->result = $q;
     $this->pos = 0;
     $q = PVars::get()->queries + 1;
     PVars::register('queries', $q);
     if (PVars::get()->debug) {
         $q = PVars::get()->query_history;
         $query_time = sprintf("%.1f", (microtime(true) - $start_time) * 1000);
         $q[] = "({$query_time} ms) {$query}";
         PVars::register('query_history', $q);
     }
     return true;
 }
Esempio n. 2
0
 /**
  * connector
  * 
  * there will be only one connection instance
  * 
  * @param array $args
  * @param string $user
  * @param string $password
  * @return PDB_mysql
  */
 protected static function connect($args, $user = false, $password = false)
 {
     if (!isset(self::$_instance)) {
         $c = __CLASS__;
         self::$_instance = new $c();
         if (PVars::get()->debug) {
             $t = microtime();
             PSurveillance::setPoint('connect' . $t);
         }
         if (!isset($args['host'])) {
             throw new PException('Host not set!');
         }
         if (!isset($args['dbname'])) {
             throw new PException('DB name not set!');
         }
         $cr = @mysql_connect($args['host'], $user, $password, true);
         if (!$cr) {
             throw new PException('Could not connect!');
         }
         self::$_instance->_cr = $cr;
         if (!@mysql_select_db($args['dbname'])) {
             throw new PException('Could not select DB: ' . $args['dbname'] . '!');
         }
         self::$_instance->_dbname = $args['dbname'];
         $queries = array("SET NAMES 'utf8'", "SET CHARACTER SET 'utf8'", "SET collation_connection='utf8_general_ci'");
         foreach ($queries as $query) {
             $q = self::$_instance->query($query);
             if (!$q) {
                 throw new PException('MySQL collation error!', 1000);
             }
         }
         if (PVars::get()->debug) {
             PSurveillance::setPoint('eoconnect' . $t);
         }
     }
     return self::$_instance;
 }