示例#1
0
 /**
  * Test mysql_free_result
  *
  * @return boolean
  */
 public function MySQL_Free_Result_Test()
 {
     $sql = 'SELECT * FROM ' . TEST_TABLE;
     $query1 = mysql_query($sql);
     $count1 = 0;
     // Validate query to avoid throwing errors
     while (is_resource_custom($query1) && get_resource_type_custom($query1) == 'mysql result' && ($row = mysql_fetch_assoc($query1))) {
         $count1++;
         mysql_free_result($query1);
     }
     return $count1 === 1;
 }
示例#2
0
 /**
  * Execute a prepared query statement helper method.
  *
  * @param mixed $result_class string which specifies which result class to use
  * @param mixed $result_wrap_class string which specifies which class to wrap results in
  * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
  * @access private
  */
 function &_execute($result_class = true, $result_wrap_class = false)
 {
     if (is_null($this->statement)) {
         $result =& parent::_execute($result_class, $result_wrap_class);
         return $result;
     }
     $this->db->last_query = $this->query;
     $this->db->debug($this->query, 'execute', array('is_manip' => $this->is_manip, 'when' => 'pre', 'parameters' => $this->values));
     if ($this->db->getOption('disable_query')) {
         $result = $this->is_manip ? 0 : null;
         return $result;
     }
     $connection = $this->db->getConnection();
     if (PEAR::isError($connection)) {
         return $connection;
     }
     $query = 'EXECUTE ' . $this->statement;
     if (!empty($this->positions)) {
         $parameters = array();
         foreach ($this->positions as $parameter) {
             if (!array_key_exists($parameter, $this->values)) {
                 return $this->db->customRaiseError(MDB2_ERROR_NOT_FOUND, null, null, 'Unable to bind to missing placeholder: ' . $parameter, __FUNCTION__);
             }
             $value = $this->values[$parameter];
             $type = array_key_exists($parameter, $this->types) ? $this->types[$parameter] : null;
             if (is_resource_custom($value) || $type == 'clob' || $type == 'blob') {
                 if (!is_resource_custom($value) && preg_match('/^(\\w+:\\/\\/)(.*)$/', $value, $match)) {
                     if ($match[1] == 'file://') {
                         $value = $match[2];
                     }
                     $value = @fopen($value, 'r');
                     $close = true;
                 }
                 if (is_resource_custom($value)) {
                     $data = '';
                     while (!@feof($value)) {
                         $data .= @fread($value, $this->db->options['lob_buffer_length']);
                     }
                     if ($close) {
                         @fclose($value);
                     }
                     $value = $data;
                 }
             }
             $param_query = 'SET @' . $parameter . ' = ' . $this->db->quote($value, $type);
             $result = $this->db->_doQuery($param_query, true, $connection);
             if (PEAR::isError($result)) {
                 return $result;
             }
         }
         $query .= ' USING @' . implode(', @', array_values($this->positions));
     }
     $result = $this->db->_doQuery($query, $this->is_manip, $connection);
     if (PEAR::isError($result)) {
         return $result;
     }
     if ($this->is_manip) {
         $affected_rows = $this->db->_affectedRows($connection, $result);
         return $affected_rows;
     }
     $result =& $this->db->_wrapResult($result, $this->result_types, $result_class, $result_wrap_class, $this->limit, $this->offset);
     $this->db->debug($this->query, 'execute', array('is_manip' => $this->is_manip, 'when' => 'post', 'result' => $result));
     return $result;
 }