コード例 #1
0
 /**
  * prepares a statement
  * 
  * returns the key of the statement
  * 
  * @param string $statement
  * @return int
  */
 public function prepare($statement)
 {
     if (PVars::get()->debug) {
         $tm = microtime();
         PSurveillance::setPoint('statement_prepare' . $tm);
     }
     if (isset($this->result) && $this->result) {
         $this->result->close();
         unset($this->result);
     }
     $statement = $this->_dao->MySQLi->prepare($statement);
     if (!$statement) {
         $e = new PException('Could not prepare statement!', 1000);
         $e->addInfo($this->_dao->getErrNo());
         $e->addInfo($this->_dao->getErrMsg());
         throw $e;
     }
     $this->_statement[] = $statement;
     end($this->_statement);
     $k = key($this->_statement);
     $this->_bound = array();
     if (PVars::get()->debug) {
         PSurveillance::setPoint('eostatement_prepare' . $tm);
     }
     $this->_i = $k;
     return $k;
 }
コード例 #2
0
ファイル: db_mysqli.lib.php プロジェクト: gpuenteallott/rox
 /**
  * connector
  * 
  * there will be only one connection instance
  * 
  * @param array $args
  * @param string $user
  * @param string $password
  * @return PDB_mysqli
  */
 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!');
         }
         $mysqli = @new mysqli($args['host'], $user, $password, $args['dbname']);
         if (!$mysqli || mysqli_connect_errno()) {
             $E = new PException('Could not connect!');
             $E->addInfo(mysqli_connect_error());
             throw $E;
         }
         self::$_instance->_MySQLi = $mysqli;
         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->exec($query);
             if (!$q) {
                 throw new PException('MySQL collation error!', 1000);
             }
         }
         if (PVars::get()->debug) {
             PSurveillance::setPoint('eoconnect' . $t);
         }
     }
     return self::$_instance;
 }