Example #1
0
 /**
  * 查询并返回结果集连接
  * @param String $sql
  * @return resource
  */
 private function _query($sql, $logSql = true)
 {
     Pft_Debug::addInfoToDefault('', "Pre execute sql");
     //self::autoSelectDbBySql( $sql );
     //return mysql_query( $sql, $this->_conn );
     //如果return $rs 会慢 数十毫秒 @todo  再次验证
     if ($this->_mutile_read_db) {
         //if ( is_object($this->_connection) && $this->_connection->getAutoCommit() ){
         if ('Pft_Dbx' == get_class($this)) {
             self::superUpdateConnectionX();
         } else {
             self::superUpdateConnection();
             // 强制更新数据库连接,使只需只读的操作连接到“只读数据库服务器”
         }
         //}
     }
     $rev = mysql_query($sql, $this->_conn);
     Pft_Debug::addInfoToDefault(__FILE__, "Executed sql [<div> {$sql} </div>]");
     if (mysql_errno()) {
         //如果使用System级别会重复记录db日志,可能死循环。
         if ($this->_log) {
             Pft_Log::addLog('Execute sql [' . $sql . '] fail, error [' . mysql_errno() . ':' . mysql_error() . ']', Pft_Log::LEVEL_DEBUG);
         }
         throw new Pft_Db_Exception(mysql_errno() . ": " . mysql_error() . "\n");
     }
     if ($logSql) {
         if ($this->_log) {
             Pft_Log::logDbOprate($sql);
         }
     }
     return $rev;
 }