/**
  * Execute the query
  *
  * @access	private called by the base class
  * @param	string	an SQL query
  * @return	resource
  */
 function _execute($sql)
 {
     $sql = $this->_prep_query($sql);
     $result = @mysqli_query($this->conn_id, $sql);
     while (mysqli_more_results($this->conn_id)) {
         mysqli_next_result($this->conn_id);
         $temp = mysqli_use_result($this->conn_id);
         if ($temp) {
             mysqli_free_result($temp);
         }
     }
     return $result;
     //		$sql = $this->_prep_query($sql);
     //		$result = @mysqli_query($this->conn_id, $sql);
     //		return $result;
 }
Example #2
0
function cleanupExtraResults($dbConn)
{
    // While there are more results, free them
    while (mysqli_next_result($dbConn)) {
        $set = mysqli_use_result($dbConn);
        if ($set instanceof mysqli_results) {
            mysqli_free_result($set);
        }
    }
}
Example #3
0
function free_mysqli_results()
{
    while (mysqli_next_result($_SESSION['mysqli_link'])) {
        //free each result.
        $result = mysqli_use_result($_SESSION['mysqli_link']);
        if ($result instanceof mysqli_result) {
            $result->free();
        }
    }
}
Example #4
0
 function get_debug_info($query)
 {
     $data = array();
     if (substr(trim(strtoupper($query)), 0, 6) == 'SELECT') {
         mysqli_real_query($this->connection, "EXPLAIN {$query}") or error(QUICKSILVER_QUERY_ERROR, mysqli_error($this->connection), $query, mysqli_errno($this->connection));
         $result = mysqli_use_result($this->connection);
         $data = mysqli_fetch_array($result, MYSQLI_ASSOC);
         mysqli_free_result($result);
     }
     return $data;
 }
Example #5
0
function istable($table)
{
    global $mysqli;
    mysqli_real_query($mysqli, "SELECT 1 FROM `{$table}` LIMIT 1 ");
    mysqli_use_result($mysqli);
    if (mysqli_errno($mysqli) == 1146) {
        return false;
    } else {
        return true;
    }
}
 private function testMysqli()
 {
     $connection = mysqli_connect($this->host, $this->user, $this->pass, $this->db, $this->port) or $this->error("Unable to connect:" . mysqli_connect_error());
     $rows = [];
     if (mysqli_multi_query($connection, "SHOW TABLES FROM {$this->db};")) {
         do {
             if ($result = mysqli_use_result($connection)) {
                 while ($row = mysqli_fetch_row($result)) {
                     $rows[] = $row[0];
                 }
                 if (!mysqli_more_results($connection)) {
                     break;
                 }
                 mysqli_free_result($result);
             }
         } while (mysqli_next_result($connection));
     }
     mysqli_close($connection);
     return $rows;
 }
Example #7
0
function domy($query)
{
    $link = $GLOBALS["C"]["sql"]["i"];
    $data = array();
    if (mysqli_multi_query($link, $query)) {
        do {
            /* store first result set */
            if ($result = mysqli_use_result($link)) {
                while ($row = mysqli_fetch_row($result)) {
                    $data[] = $row;
                }
                mysqli_free_result($result);
            }
            /* print divider 
               if (mysqli_more_results($link)) {
                   printf("-----------------\n");
               }*/
        } while (mysqli_next_result($link));
    }
    return $data;
}
Example #8
0
 function mysql_unbuffered_query($query, \mysqli $link = null)
 {
     $link = \Dshafik\MySQL::getConnection($link);
     if (mysqli_real_query($link, $query)) {
         return mysqli_use_result($link);
     }
     return false;
 }
if (NULL !== ($tmp = @mysqli_real_query($link, "SELECT 1 AS a", MYSQLI_USE_RESULT, "foo"))) {
    printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
}
if (false !== ($tmp = mysqli_real_query($link, 'THIS IS NOT SQL'))) {
    printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
}
if (false !== ($tmp = mysqli_real_query($link, "SELECT 'this is sql but with backslash g'\\g"))) {
    printf("[005] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
}
if (0 === mysqli_errno($link) || '' == mysqli_error($link)) {
    printf("[006] mysqli_errno()/mysqli_error should return some error\n");
}
if (!mysqli_real_query($link, "SELECT 'this is sql but with semicolon' AS valid ; ")) {
    printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
if (!is_object($res = mysqli_use_result($link))) {
    printf("[008] Expecting reseult object, got %s/%s [%d] %s\n", gettype($res), $res, mysqli_errno($link), mysqli_error($link));
}
var_dump(mysqli_fetch_assoc($res));
mysqli_free_result($res);
if (false !== ($res = mysqli_real_query($link, "SELECT 'this is sql but with semicolon' AS valid ; SHOW VARIABLES"))) {
    printf("[008] Expecting boolean/false, got %s/%s, [%d] %s\n", gettype($res), $res, mysqli_errno($link), mysqli_error($link));
}
if (mysqli_get_server_version($link) > 50000) {
    // let's try to play with stored procedures
    mysqli_real_query($link, 'DROP PROCEDURE IF EXISTS p');
    if (mysqli_real_query($link, 'CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) BEGIN SELECT VERSION() INTO ver_param;
END;')) {
        mysqli_real_query($link, 'CALL p(@version)');
        mysqli_real_query($link, 'SELECT @version AS p_version');
        $res = mysqli_store_result($link);
    printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
}
if (!is_null($tmp = @mysqli_free_result($link))) {
    printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
}
require 'table.inc';
if (!($res = mysqli_query($link, "SELECT id FROM test ORDER BY id LIMIT 1"))) {
    printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
print "a\n";
var_dump(mysqli_free_result($res));
print "b\n";
var_dump(mysqli_free_result($res));
if (!($res = mysqli_query($link, "SELECT id FROM test ORDER BY id LIMIT 1"))) {
    printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
print "c\n";
var_dump($res = mysqli_store_result($link));
var_dump(mysqli_error($link));
print "[005]\n";
var_dump(mysqli_free_result($res));
if (!($res = mysqli_query($link, "SELECT id FROM test ORDER BY id LIMIT 1"))) {
    printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
print "d\n";
var_dump($res = mysqli_use_result($link));
var_dump(mysqli_error($link));
print "[007]\n";
var_dump(mysqli_free_result($res));
mysqli_close($link);
print "done!";
Example #11
0
 /**
  * 调用存储过程
  *
  * @param string $sql
  */
 function call($sql)
 {
     $results = array();
     $this->multi_query($sql);
     do {
         if ($result = mysqli_use_result($this->link_id)) {
             while ($row = $this->fetch_array($result)) {
                 $results[] = $row;
             }
         }
     } while (mysqli_more_results($this->link_id) && mysqli_next_result($this->link_id));
     return $results;
 }
if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) {
    printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", $host, $user, $db, $port, $socket);
}
if (!mysqli_real_query($link, "SELECT id, label FROM test_mysqli_result_references_table_1 ORDER BY id ASC LIMIT 2") || !($res = mysqli_use_result($link))) {
    printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
while ($row = mysqli_fetch_assoc($res)) {
    /* mysqlnd: force seperation - create copies*/
    $references[$idx] = array('id' => &$row['id'], 'label' => $row['label'] . '');
    $references[$idx]['id2'] =& $references[$idx]['id'];
    $references[$idx]['id'] += 1;
    $references[$idx++]['id2'] += 1;
}
$references[$idx++] =& $res;
mysqli_free_result($res);
@debug_zval_dump($references);
if (!mysqli_real_query($link, "SELECT id, label FROM test_mysqli_result_references_table_1 ORDER BY id ASC LIMIT 1") || !($res = mysqli_use_result($link))) {
    printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
$tmp = array();
while ($row = mysqli_fetch_assoc($res)) {
    $tmp[] = $row;
}
$tmp = unserialize(serialize($tmp));
debug_zval_dump($tmp);
mysqli_free_result($res);
mysqli_close($link);
print "done!";
error_reporting(0);
$test_table_name = 'test_mysqli_result_references_table_1';
require_once "clean_table.inc";
    }
    print trim($tmp) . "\n";
}
if (!mysqli_multi_query($link, "SELECT 1 AS a; SELECT 1 AS a, 2 AS b; SELECT id FROM test ORDER BY id LIMIT 3")) {
    printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
print "[010]\n";
$i = 1;
if (mysqli_get_server_version($link) > 41000 && !($ret = mysqli_more_results($link))) {
    printf("[011] Expecting boolean/true, got %s/%s\n", gettype($ret), $ret);
}
if ($strict_on) {
    ob_start();
}
do {
    $res = mysqli_use_result($link);
    // NOTE: if you use mysqli_use_result() with mysqli_more_results() or any other info function,
    // you must fetch all rows before you can loop to the next result set!
    // See also the MySQL Reference Manual: mysql_use_result()
    while ($row = mysqli_fetch_array($res)) {
    }
    mysqli_free_result($res);
    if (mysqli_more_results($link)) {
        printf("%d\n", $i++);
    }
} while (mysqli_next_result($link));
if ($strict_on) {
    $tmp = ob_get_contents();
    ob_end_clean();
    if (!preg_match('@Strict Standards: mysqli_next_result\\(\\): There is no next result set@ismU', $tmp)) {
        printf("[008] Strict Standards warning missing\n");
Example #14
0
function dbquery($sql, $limit = 1, $multi = false)
{
    if (!is_string($sql) || !($sql = trim($sql))) {
        return false;
    }
    $ck = md5($sql);
    if ($ret = cache($ck)) {
        return $ret;
    }
    global $dblink;
    $cn = "{$sql}-{$limit}-{$multi}";
    $cmd = strtolower(substr($sql, 0, strpos($sql, ' ')));
    if ($cmd == 'select') {
        if ($limit == -1) {
            $limit = '18446744073709551615';
        }
        $sql .= " limit {$limit}";
    }
    if ($multi) {
        $res = mysqli_multi_query($dblink, $sql);
    } else {
        $res = mysqli_query($dblink, $sql);
    }
    if (!$res) {
        return false;
    }
    if ($multi) {
        $ret = [];
        for ($res = mysqli_use_result($dblink); $res; $res = mysqli_store_result($dblink)) {
            $r = [];
            while ($t = mysqli_fetch_assoc($res)) {
                $r[] = $t;
            }
            $ret[] = $r;
            mysqli_free_result($res);
            mysqli_next_result($dblink);
        }
    } else {
        switch ($cmd) {
            case 'select':
            case 'call':
                if ($cmd == 'select' && $limit == '1') {
                    $ret = mysqli_fetch_assoc($res);
                    break;
                }
                $ret = [];
                while ($t = mysqli_fetch_assoc($res)) {
                    $ret[] = $t;
                }
                break;
            case 'insert':
                $ret = mysqli_insert_id($dblink);
                if (!$ret) {
                    $ret = true;
                }
                break;
            case 'delete':
                $ret = mysqli_affected_rows($dblink);
                break;
            default:
                $ret = $res;
                break;
        }
    }
    return $ret;
}
Example #15
0
 public static function request2($sqlStatement, $checkSession, $config = null, $useDbOperator = false)
 {
     if ($config === null) {
         // loads the mysql server config from file
         $config = parse_ini_file('config.ini', TRUE);
     }
     //ini_set('mysql.connect_timeout','60');
     // creates a new connection to database
     if (!isset($config['ZV']['zv_type']) || isset($config['ZV']['zv_type']) && $config['ZV']['zv_type'] == 'local') {
         $path = strpos($config['PL']['urlExtern'], $config['DB']['db_path']) === false ? $config['DB']['db_path'] : 'localhost';
     } else {
         $path = $config['DB']['db_path'];
     }
     if (!$useDbOperator) {
         $dbconn = @mysqli_connect($path, $config['DB']['db_user'], $config['DB']['db_passwd'], $config['DB']['db_name']);
     } else {
         $dbconn = @mysqli_connect($path, $config['DB']['db_user_operator'], $config['DB']['db_passwd_operator'], $config['DB']['db_name']);
     }
     if (!$dbconn) {
         $query_result['errno'] = 10;
         return $query_result;
     }
     // use UTF8
     mysqli_set_charset($dbconn, "utf8");
     $currentTime = $_SERVER['REQUEST_TIME'];
     // check session
     ///if (error_reporting() & E_NOTICE)
     $checkSession = false;
     // remove the comment this line to disable the session examination
     // Storing whether or not a session condition is not satisfied
     $sessionFail = false;
     if ($checkSession === true) {
         Logger::Log('starts session validation', LogLevel::DEBUG);
         if (isset($_SERVER['HTTP_SESSION']) && isset($_SERVER['HTTP_USER']) && isset($_SERVER['HTTP_DATE']) && ctype_digit($_SERVER['HTTP_USER']) && (int) $_SERVER['REQUEST_TIME'] <= (int) $_SERVER['HTTP_DATE'] + 45 * 60) {
             $content = mysqli_query($dbconn, 'select SE_sessionID from Session where U_id = ' . $_SERVER['HTTP_USER']);
             // evaluates the session
             $errno = mysqli_errno($dbconn);
             if ($errno == 0 && gettype($content) != 'boolean') {
                 $data = DBJson::getRows2($content);
                 if ($data != null && $data[0]['SE_sessionID'] == $_SERVER['HTTP_SESSION']) {
                     $sessionFail = false;
                 } else {
                     $sessionFail = true;
                 }
             } else {
                 $sessionFail = true;
             }
         } else {
             $sessionFail = true;
         }
     }
     // if a condition is not met, the request is invalid
     if ($sessionFail == true) {
         $query_result['content'] = '';
         $query_result['errno'] = 401;
         $query_result['error'] = 'access denied';
         $query_result['numRows'] = 0;
         mysqli_close($dbconn);
         $dbconn = null;
         return array($query_result);
     }
     // performs the request
     $answ = mysqli_multi_query($dbconn, $sqlStatement);
     $query_result = array();
     if ($answ === false) {
         $result = array();
         $result['affectedRows'] = mysqli_affected_rows($dbconn);
         $result['insertId'] = mysqli_insert_id($dbconn);
         $result['errno'] = mysqli_errno($dbconn);
         $result['error'] = mysqli_error($dbconn);
         $query_result[] = $result;
     } else {
         do {
             $result = array();
             $res = null;
             if ($res = mysqli_use_result($dbconn)) {
                 $hash = '';
                 $result['content'] = DBJson::getRows2($res, $hash);
                 $result['hash'] = $hash;
                 $result['numRows'] = count($result['content']);
                 // evaluates the request
                 $result['affectedRows'] = mysqli_affected_rows($dbconn);
                 $result['insertId'] = mysqli_insert_id($dbconn);
                 $result['errno'] = mysqli_errno($dbconn);
                 $result['error'] = mysqli_error($dbconn);
                 mysqli_free_result($res);
             } else {
                 $hash = '';
                 $result['content'] = null;
                 $result['hash'] = $hash;
                 $result['affectedRows'] = mysqli_affected_rows($dbconn);
                 $result['insertId'] = mysqli_insert_id($dbconn);
                 $result['errno'] = mysqli_errno($dbconn);
                 $result['error'] = mysqli_error($dbconn);
             }
             $query_result[] = $result;
         } while (mysqli_more_results($dbconn) && mysqli_next_result($dbconn));
     }
     // closes the connection and returns the result
     mysqli_close($dbconn);
     $dbconn = null;
     return $query_result;
 }
require_once 'table.inc';
$references = array();
if (!mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 1") || !($res = mysqli_store_result($link))) {
    printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
$idx = 0;
while ($row = mysqli_fetch_assoc($res)) {
    /* will overwrite itself */
    $references[$idx]['row_ref'] =& $row;
    $references[$idx]['row_copy'] = $row;
    $references[$idx]['id_ref'] =& $row['id'];
    $references[$idx++]['id_copy'] = $row['id'];
}
debug_zval_dump($references);
mysqli_free_result($res);
if (!mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2") || !($res = mysqli_use_result($link))) {
    printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
$rows = array();
for ($i = 0; $i < 2; $i++) {
    $rows[$i] = mysqli_fetch_assoc($res);
    $references[$idx]['row_ref'] =& $rows[$i];
    $references[$idx]['row_copy'] = $rows[$i];
    $references[$idx]['id_ref'] =& $rows[$i]['id'];
    $references[$idx]['id_copy'] = $rows[$i]['id'];
    /* enforce separation */
    $references[$idx]['id_copy_mod'] = $rows[$i]['id'] + 0;
}
mysqli_free_result($res);
debug_zval_dump($references);
print "done!";
Example #17
0
 function dbCleanConnection($dbh = false)
 {
     if (!$dbh) {
         $dbh = \CB\Cache::get('dbh');
     }
     while (mysqli_more_results($dbh)) {
         if (mysqli_next_result($dbh)) {
             $result = mysqli_use_result($dbh);
             if (is_object($result)) {
                 mysql_free_result($result);
             }
         }
     }
 }
Example #18
0
 /**
  * @since 08.05.2011
  * Refactored for using $this::mysqli_connection instead of mysqli_init/mysqli_close
  */
 public function executeSP($query, &$resultArry, $assoc = TRUE)
 {
     $link = $this->getMysqliConnection();
     //do queries
     if (mysqli_multi_query($link, $query)) {
         $sqlResult = mysqli_store_result($link);
         if ($result) {
             //$rowsAffected = mysqli_num_rows($result);
             if ($assoc) {
                 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
                     $resultArry[] = $row;
                 }
             } else {
                 while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) {
                     $resultArry[] = $row;
                 }
             }
             mysqli_free_result($result);
             unset($result);
         }
         if (mysqli_more_results($link)) {
             while (mysqli_next_result($link)) {
                 $sqlResult = mysqli_use_result($link);
                 if ($sqlResult instanceof mysqli_result) {
                     mysqli_free_result($sqlResult);
                 }
             }
         }
     } else {
         throw new DBAdapter2Exception('Error in query: ' . mysqli_error($link));
     }
 }
Example #19
0
 public function executeSP($query, &$resultArry, $assoc = TRUE)
 {
     $l_iTries = 3;
     //times
     $l_iPause = 2;
     //seconds
     $l_bConnected = FALSE;
     //bool
     do {
         $link = mysqli_init();
         //$rowsAffected=0;
         if (!$link) {
             throw new DBAdapter2Exception("mysqli_init failed");
         }
         if (!mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, 10)) {
             throw new DBAdapter2Exception("Setting MYSQLI_OPT_CONNECT_TIMEOUT failed");
         }
         if (!mysqli_real_connect($link, $this->host, $this->username, $this->password, $this->schema)) {
             //throw new DBAdapter2Exception('Connect Error For Stored Procedure (' . mysqli_connect_errno() . ') '. mysqli_connect_error());
             unset($link);
             sleep($l_iPause);
             $l_iTries = $l_iTries - 1;
         } else {
             $l_bConnected = TRUE;
             $l_iTries = 0;
         }
     } while (!$l_bConnected && $l_iTries > 0);
     if (!$l_bConnected) {
         throw new DBAdapter2Exception('Connect Error For Stored Procedure (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
     }
     if (!mysqli_set_charset($link, $this->charset)) {
         throw new DBAdapter2Exception('Error loading character set ' . $this->charset . ' - ' . mysqli_error($link));
     }
     //do queries
     if (mysqli_multi_query($link, $query)) {
         $sqlResult = mysqli_store_result($link);
         if ($result) {
             //$rowsAffected = mysqli_num_rows($result);
             if ($assoc) {
                 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
                     $resultArry[] = $row;
                 }
             } else {
                 while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) {
                     $resultArry[] = $row;
                 }
             }
             mysqli_free_result($result);
             unset($result);
         }
         if (mysqli_more_results($link)) {
             while (mysqli_next_result($link)) {
                 $sqlResult = mysqli_use_result($link);
                 if ($sqlResult instanceof mysqli_result) {
                     mysqli_free_result($sqlResult);
                 }
             }
         }
     } else {
         throw new DBAdapter2Exception('Error in query: ' . mysqli_error($link));
     }
     mysqli_close($link);
 }
Example #20
0
 private static function _call($method, $args)
 {
     $args = self::processArgs($args);
     $sql = "CALL {$method}(" . implode(',', $args) . ");";
     self::freeResult();
     $result = array();
     if (mysqli_real_query(self::$link, $sql)) {
         do {
             $r = mysqli_use_result(self::$link);
             if ($r && !is_bool($r)) {
                 while ($row = mysqli_fetch_object($r)) {
                     $result[] = $row;
                 }
                 mysqli_free_result($r);
             }
         } while (mysqli_next_result(self::$link));
     }
     return $result;
 }
 if (isset($_POST["multiquery"])) {
     // try multi query mode
     $query = rawUrlDecode($_POST["multiquery"]);
     $result = mysqli_multi_query($mysqli, $query);
     if ($result === FALSE) {
         echo "Query did not work. \n";
         echo mysqli_error($mysqli);
     } else {
         if ($result === 0) {
             echo "No results returned";
         } else {
             // first result is just setting a variable. ignore it.
             $result = mysqli_use_result($mysqli);
             if (mysqli_next_result($mysqli)) {
                 // second result is the actual data.
                 $result = mysqli_use_result($mysqli);
                 $myArray = array();
                 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
                     $tempArray = $row;
                     // some strings contain f****d up characters
                     //$tempArray["tweet"] = stripslashes($tempArray["tweet"]);
                     //$tempArray["user_name"] = stripslashes($tempArray["user_name"]);
                     array_push($myArray, $tempArray);
                 }
                 echo json_encode($myArray);
             }
             mysqli_close($mysqli);
         }
     }
 } else {
     // try single query mode (which surely works..)
Example #22
0
 /**
  *  結果データを構築する
  *
  *  結果セットを取得する
  *    - 一括、逐次読み込みを任意に設定する場合は引数で指定する
  *    - デフォルトは一括読み込みとする
  *
  *  @param   boolean  結果セットを一括読み込みする場合TRUE
  *  @retrun  boolean  TRUE:成功時
  */
 protected function use_or_store_result($store_result)
 {
     // 結果データを返さない場合はそのまま終了
     if (mysqli_field_count($this->le_link) < 1) {
         return TRUE;
     }
     // 結果データを取得
     set_error_handler(array($this, 'php_error_handler'));
     $le_result = $store_result ? mysqli_store_result($this->le_link) : mysqli_use_result($this->le_link);
     restore_error_handler();
     if ($le_result === FALSE) {
         return FALSE;
     }
     // フィールド情報を取得する
     foreach (mysqli_fetch_fields($le_result) as $field) {
         $tmp = array(self::FIELD_DEF_IS_POS => count($this->def_fields), self::FIELD_DEF_IS_TYPE => $field->type, self::FIELD_DEF_IS_NAME => $field->name, self::FIELD_DEF_IS_NAME_ORIG => $field->orgname, self::FIELD_DEF_IS_TABLE => $field->table, self::FIELD_DEF_IS_TABLE_ORIG => $field->orgtable);
         // MEMO : 底層レベルのバグでorgnameが取得できない場合がある
         if (strlen($field->orgname) < 1) {
             $this->def_fields[$field->name] = $tmp;
         } else {
             $this->def_fields[$field->orgname] = $tmp;
         }
     }
     $this->le_result = $le_result;
     $this->affected_rows = mysqli_num_rows($le_result);
 }
Example #23
0
 function NextRecordSet()
 {
     global $ADODB_COUNTRECS;
     mysqli_free_result($this->_queryID);
     $this->_queryID = -1;
     // Move to the next recordset, or return false if there is none. In a stored proc
     // call, mysqli_next_result returns true for the last "recordset", but mysqli_store_result
     // returns false. I think this is because the last "recordset" is actually just the
     // return value of the stored proc (ie the number of rows affected).
     if (!mysqli_next_result($this->connection->_connectionID)) {
         return false;
     }
     // CD: There is no $this->_connectionID variable, at least in the ADO version I'm using
     $this->_queryID = $ADODB_COUNTRECS ? @mysqli_store_result($this->connection->_connectionID) : @mysqli_use_result($this->connection->_connectionID);
     if (!$this->_queryID) {
         return false;
     }
     $this->_inited = false;
     $this->bind = false;
     $this->_currentRow = -1;
     $this->Init();
     return true;
 }
Example #24
0
 /**
  * This method is the central method for handling database
  * interaction. The method can be used for setting up a database
  * connection, for running a SQL query and for returning query rows.
  * Which of these actions the method will handle and what the method
  * return data will be, is determined by the $return method parameter.
  *
  * @param $return   - What to return. Options are the following constants:
  *                    DB_RETURN_CONN      a db connection handle
  *                    DB_RETURN_QUOTED    a quoted parameter
  *                    DB_RETURN_RES       result resource handle
  *                    DB_RETURN_ROW       single row as array
  *                    DB_RETURN_ROWS      all rows as arrays
  *                    DB_RETURN_ASSOC     single row as associative array
  *                    DB_RETURN_ASSOCS    all rows as associative arrays
  *                    DB_RETURN_VALUE     single row, single column
  *                    DB_RETURN_ROWCOUNT  number of selected rows
  *                    DB_RETURN_NEWID     new row id for insert query
  *                    DB_RETURN_ERROR     an error message if the query
  *                                        failed or NULL if there was
  *                                        no error
  *                    DB_CLOSE_CONN       close the connection, no
  *                                        return data
  *
  * @param $sql      - The SQL query to run or the parameter to quote if
  *                    DB_RETURN_QUOTED is used.
  *
  * @param $keyfield - When returning an array of rows, the indexes are
  *                    numerical by default (0, 1, 2, etc.). However, if
  *                    the $keyfield parameter is set, then from each
  *                    row the $keyfield index is taken as the key for the
  *                    return array. This way, you can create a direct
  *                    mapping between some id field and its row in the
  *                    return data. Mind that there is no error checking
  *                    at all, so you have to make sure that you provide
  *                    a valid $keyfield here!
  *
  * @param $flags    - Special flags for modifying the method's behavior.
  *                    These flags can be OR'ed if multiple flags are needed.
  *                    DB_NOCONNECTOK     Failure to connect is not fatal
  *                                       but lets the call return FALSE
  *                                       (useful in combination with
  *                                       DB_RETURN_CONN).
  *                    DB_MISSINGTABLEOK  Missing table errors not fatal.
  *                    DB_DUPFIELDNAMEOK  Duplicate field errors not fatal.
  *                    DB_DUPKEYNAMEOK    Duplicate key name errors
  *                                       not fatal.
  *                    DB_DUPKEYOK        Duplicate key errors not fatal.
  *
  * @param $limit    - The maximum number of rows to return.
  * @param $offset   - The number of rows to skip in the result set,
  *                    before returning rows to the caller.
  *
  * @return $res     - The result of the query, based on the $return
  *                    parameter.
  */
 public function interact($return, $sql = NULL, $keyfield = NULL, $flags = 0, $limit = 0, $offset = 0)
 {
     static $conn;
     static $querytrack;
     // Close the database connection.
     if ($return == DB_CLOSE_CONN) {
         if (!empty($conn)) {
             mysqli_close($conn);
             $conn = null;
         }
         return;
     }
     $debug = empty($GLOBALS['PHORUM']['DBCONFIG']['dbdebug']) ? 0 : $GLOBALS['PHORUM']['DBCONFIG']['dbdebug'];
     if (!empty($debug)) {
         if (!isset($querytrack) || !is_array($querytrack)) {
             $querytrack = array('count' => 0, 'time' => 0, 'queries' => array());
         }
     }
     // Setup a database connection if no database connection is
     // available yet.
     if (empty($conn)) {
         global $PHORUM;
         // we suppress errors from the mysqli_connect command as errors
         // are catched differently.
         $conn = mysqli_connect($PHORUM['DBCONFIG']['server'], $PHORUM['DBCONFIG']['user'], $PHORUM['DBCONFIG']['password'], $PHORUM['DBCONFIG']['name'], $PHORUM['DBCONFIG']['port'], $PHORUM['DBCONFIG']['socket']);
         if ($conn === FALSE) {
             if ($flags & DB_NOCONNECTOK) {
                 return FALSE;
             }
             phorum_api_error(PHORUM_ERRNO_DATABASE, 'Failed to connect to the database.');
             exit;
         }
         if (!empty($PHORUM['DBCONFIG']['charset'])) {
             $set_names = "SET NAMES '{$PHORUM['DBCONFIG']['charset']}'";
             mysqli_query($conn, $set_names);
             if ($debug) {
                 $querytrack['count'] += 2;
                 if ($debug > 1) {
                     $querytrack['queries'][] = array('number' => '001', 'query' => htmlspecialchars($set_names), 'raw_query' => $set_names, 'time' => '0.000');
                 }
             }
         }
         // putting this here for testing mainly
         // All of Phorum should work in strict mode
         if (!empty($PHORUM["DBCONFIG"]["strict_mode"])) {
             mysqli_query($conn, "SET SESSION sql_mode='STRICT_ALL_TABLES'");
         }
     }
     // RETURN: quoted parameter.
     if ($return === DB_RETURN_QUOTED) {
         return mysqli_real_escape_string($conn, $sql);
     }
     // RETURN: database connection handle
     if ($return === DB_RETURN_CONN) {
         return $conn;
     }
     // By now, we really need a SQL query.
     if ($sql === NULL) {
         trigger_error(__METHOD__ . ': Internal error: ' . 'missing sql query statement!', E_USER_ERROR);
     }
     // Apply limit and offset to the query.
     settype($limit, 'int');
     settype($offset, 'int');
     if ($limit > 0) {
         $sql .= " LIMIT {$limit}";
     }
     if ($offset > 0) {
         $sql .= " OFFSET {$offset}";
     }
     // Execute the SQL query.
     $tries = 0;
     $res = FALSE;
     while ($res === FALSE && $tries < 3) {
         // Time the query for debug level 2 and up.
         if ($debug > 1) {
             $t1 = microtime(TRUE);
         }
         // For queries where we are going to retrieve multiple rows, we
         // use an unuffered query result.
         if ($return === DB_RETURN_ASSOCS || $return === DB_RETURN_ROWS) {
             $res = FALSE;
             if (mysqli_real_query($conn, $sql) !== FALSE) {
                 $res = mysqli_use_result($conn);
             }
         } else {
             $res = mysqli_query($conn, $sql);
         }
         if ($debug) {
             $querytrack['count']++;
             if ($debug > 1) {
                 $t2 = microtime(TRUE);
                 $time = sprintf("%0.3f", $t2 - $t1);
                 $querytrack['time'] += $time;
                 $querytrack['queries'][] = array('number' => sprintf("%03d", $querytrack['count']), 'query' => htmlspecialchars($sql), 'raw_query' => $sql, 'time' => $time);
             }
             $GLOBALS['PHORUM']['DATA']['DBDEBUG'] = $querytrack;
         }
         // Handle errors.
         if ($res === FALSE) {
             $errno = mysqli_errno($conn);
             // if we have an error due to a transactional storage engine,
             // retry the query for those errors up to 2 more times
             if ($tries < 3 && ($errno == 1422 || $errno == 1213 || $errno == 1205)) {
                 // 1205 Lock wait timeout
                 $tries++;
             } else {
                 // See if the $flags tell us to ignore the error.
                 $ignore_error = FALSE;
                 switch ($errno) {
                     // Table does not exist.
                     case 1146:
                         if ($flags & DB_MISSINGTABLEOK) {
                             $ignore_error = TRUE;
                         }
                         break;
                         // Table already exists.
                     // Table already exists.
                     case 1050:
                         if ($flags & DB_TABLEEXISTSOK) {
                             $ignore_error = TRUE;
                         }
                         break;
                         // Duplicate column name.
                     // Duplicate column name.
                     case 1060:
                         if ($flags & DB_DUPFIELDNAMEOK) {
                             $ignore_error = TRUE;
                         }
                         break;
                         // Duplicate key name.
                     // Duplicate key name.
                     case 1061:
                         if ($flags & DB_DUPKEYNAMEOK) {
                             $ignore_error = TRUE;
                         }
                         break;
                         // Duplicate entry for key.
                     // Duplicate entry for key.
                     case 1062:
                         // For MySQL server versions 5.1.15 up to 5.1.20. See
                         // bug #28842 (http://bugs.mysql.com/bug.php?id=28842)
                     // For MySQL server versions 5.1.15 up to 5.1.20. See
                     // bug #28842 (http://bugs.mysql.com/bug.php?id=28842)
                     case 1582:
                         if ($flags & DB_DUPKEYOK) {
                             $ignore_error = TRUE;
                         }
                         break;
                 }
                 // Handle this error if it's not to be ignored.
                 if (!$ignore_error) {
                     $err = mysqli_error($conn);
                     // RETURN: error message.
                     if ($return === DB_RETURN_ERROR) {
                         return $err;
                     }
                     // Trigger an error.
                     phorum_api_error(PHORUM_ERRNO_DATABASE, "{$err} ({$errno}): {$sql}");
                     exit;
                 }
                 // break while
                 break;
             }
         }
     }
     // RETURN: NULL (no error).
     if ($return === DB_RETURN_ERROR) {
         return NULL;
     }
     // RETURN: query resource handle
     if ($return === DB_RETURN_RES) {
         return $res;
     }
     // RETURN: number of rows
     if ($return === DB_RETURN_ROWCOUNT) {
         return $res ? mysqli_num_rows($res) : 0;
     }
     // RETURN: array rows or single value
     if ($return === DB_RETURN_ROW || $return === DB_RETURN_ROWS || $return === DB_RETURN_VALUE) {
         // Keyfields are only valid for DB_RETURN_ROWS.
         if ($return !== DB_RETURN_ROWS) {
             $keyfield = NULL;
         }
         $rows = array();
         if ($res) {
             while ($row = mysqli_fetch_row($res)) {
                 if ($keyfield === NULL) {
                     $rows[] = $row;
                 } else {
                     $rows[$row[$keyfield]] = $row;
                 }
             }
         }
         // Return all rows.
         if ($return === DB_RETURN_ROWS) {
             /* Might be FALSE in case of ignored errors. */
             if (!is_bool($res)) {
                 mysqli_free_result($res);
             }
             return $rows;
         }
         // Return a single row.
         if ($return === DB_RETURN_ROW) {
             if (count($rows) == 0) {
                 return NULL;
             } else {
                 return $rows[0];
             }
         }
         // Return a single value.
         if (count($rows) == 0) {
             return NULL;
         } else {
             return $rows[0][0];
         }
     }
     // RETURN: associative array rows
     if ($return === DB_RETURN_ASSOC || $return === DB_RETURN_ASSOCS) {
         // Keyfields are only valid for DB_RETURN_ASSOCS.
         if ($return !== DB_RETURN_ASSOCS) {
             $keyfield = NULL;
         }
         $rows = array();
         if ($res) {
             while ($row = mysqli_fetch_assoc($res)) {
                 if ($keyfield === NULL) {
                     $rows[] = $row;
                 } else {
                     $rows[$row[$keyfield]] = $row;
                 }
             }
         }
         // Return all rows.
         if ($return === DB_RETURN_ASSOCS) {
             /* Might be FALSE in case of ignored errors. */
             if (!is_bool($res)) {
                 mysqli_free_result($res);
             }
             return $rows;
         }
         // Return a single row.
         if ($return === DB_RETURN_ASSOC) {
             if (count($rows) == 0) {
                 return NULL;
             } else {
                 return $rows[0];
             }
         }
     }
     // RETURN: new id after inserting a new record
     if ($return === DB_RETURN_NEWID) {
         return mysqli_insert_id($conn);
     }
     trigger_error(__METHOD__ . ': Internal error: ' . 'illegal return type specified!', E_USER_ERROR);
 }
Example #25
0
 /**
  * @see MysqlManager::query()
  */
 protected function queryMulti($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false, $multiquery = true)
 {
     if (is_array($sql)) {
         return $this->queryArray($sql, $dieOnError, $msg, $suppress);
         //queryArray does not support any return sets
     }
     static $queryMD5 = array();
     parent::countQuery($sql);
     $GLOBALS['log']->info('Query:' . $sql);
     $this->checkConnection();
     $this->query_time = microtime(true);
     $this->lastsql = $sql;
     if ($multiquery) {
         $query_result = $suppress ? @mysqli_multi_query($this->database, $sql) : mysqli_multi_query($this->database, $sql);
         $result = mysqli_use_result($this->database);
         // Clear any remaining recordsets
         while (mysqli_next_result($this->database)) {
             $tmp_result = mysqli_use_result($this->database);
             mysqli_free_result($tmp_result);
         }
     } else {
         $result = $suppress ? @mysqli_query($this->database, $sql) : mysqli_query($this->database, $sql);
     }
     $md5 = md5($sql);
     if (empty($queryMD5[$md5])) {
         $queryMD5[$md5] = true;
     }
     $this->query_time = microtime(true) - $this->query_time;
     $GLOBALS['log']->info('Query Execution Time:' . $this->query_time);
     // slow query logging
     if ($this->dump_slow_queries($sql)) {
         $this->track_slow_queries($sql);
     }
     // This is some heavy duty debugging, leave commented out unless you need this:
     /*
       $bt = debug_backtrace();
       $line['file'] = 'NO_FILE';
       $line['line'] = 'NO_LINE';
       $line['function'] = 'NO_FUNCTION';
       $i = 0;
       foreach ( $bt as $i => $tryLine ) {
           if ( strpos($tryLine['file'],'include/database') === false && strpos($tryLine['file'],'include/SugarQuery') === false ) {
               $line = $tryLine;
               // Go function line up to find the real function
               if ( isset($bt[($i+1)]['function']) ) {
                   $line['function'] = $bt[($i+1)]['function'];
               }
               break;
           }
       }
     $dumpQuery = str_replace(array('      ','     ','    ','   ','  ',"\n","\t","\r"),
                              array(' ',     ' ',    ' ',   ' ',  ' ', ' ', ' ', ' ',),
                              $sql);
     
     $GLOBALS['log']->fatal("{$line['file']}:{$line['line']} ${line['function']} \nQuery: $dumpQuery\n");
     */
     if ($keepResult) {
         $this->lastResult = $result;
     }
     if ($this->database && mysqli_errno($this->database) == 2006 && $this->retryCount < 1) {
         $GLOBALS['log']->fatal('mysqli has gone away, retrying');
         $this->retryCount++;
         $this->disconnect();
         $this->connect();
         return $this->query($sql, $dieOnError, $msg, $suppress, $keepResult);
     } else {
         $this->retryCount = 0;
     }
     $this->checkError($msg . ' Query Failed: ' . $sql, $dieOnError);
     return $result;
 }
}
.left {
	
}
.right {
	width: 60%;
}
</style>
<h1>Ents Bookings</h1>
<p> Download in <a href="bookings_Spreadsheet.php">spreadsheet format</a>. This is a tab separated file. In order to import it into excel (or similar software) correctly, make sure the 'tab' box is the only box checked for the delimiters (comma, space, etc should be unchecked).</p>
<table>
<?php 
$cv = mysqli_connect("localhost", "mayball_admin", "XuthebAw97");
mysqli_select_db($cv, "mayball");
mysqli_real_query($cv, "SELECT ents_slots.*,ents.* FROM ents INNER JOIN ents_slots ON ents.ents_slot_id=ents_slots.ents_slot_id ORDER BY ents_slots.time;");
if ($result = mysqli_use_result($cv)) {
    while (($row = mysqli_fetch_assoc($result)) != null) {
        echo "<tr>";
        echo "<td class='left'>" . date("D jS M - g:i a", strtotime($row["time"])) . "</td>";
        echo "<td class='right'>";
        echo "<span class='label'>Act Name</span>: " . $row["act_name"] . "<br />";
        echo "<span class='label'>Act Type</span>: " . $row["act_type"] . "<br />";
        echo "<span class='label'>Genre/Description</span>: <div id='genre'>" . nl2br($row["genre"]) . "</div><br />";
        echo "<span class='label'>Contact</span>: <a href='mailto:'" . $row["contact_email"] . "'>" . $row["contact_name"] . "</a> [" . $row["contact_phone"] . "] <br />";
        echo "</td>";
        echo "</tr>";
    }
}
mysqli_free_result($result);
?>
</table>
Example #27
0
 /**
  * Move the internal result pointer to the next available result
  *
  * @return true on success, false if there is no more result set or an error object on failure
  * @access public
  */
 function nextResult()
 {
     $connection = $this->db->getConnection();
     if (PEAR::isError($connection)) {
         return $connection;
     }
     if (!@mysqli_more_results($connection)) {
         return false;
     }
     if (!@mysqli_next_result($connection)) {
         return false;
     }
     if (!($this->result = @mysqli_use_result($connection))) {
         return false;
     }
     return MDB2_OK;
 }
Example #28
0
$test_table_name = 'test_mysqli_use_result_table_1';
require 'table.inc';
if (!($res = mysqli_real_query($link, "SELECT id, label FROM test_mysqli_use_result_table_1 ORDER BY id"))) {
    printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
if (!is_object($res = mysqli_use_result($link))) {
    printf("[004] Expecting object, got %s/%s. [%d] %s\n", gettype($res), $res, mysqli_errno($link), mysqli_error($link));
}
if (false !== ($tmp = mysqli_data_seek($res, 2))) {
    printf("[005] Expecting boolean/true, got %s/%s. [%d] %s\n", gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
}
mysqli_free_result($res);
if (!mysqli_query($link, "DELETE FROM test_mysqli_use_result_table_1")) {
    printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
if (false !== ($res = mysqli_use_result($link))) {
    printf("[007] Expecting boolean/false, got %s/%s. [%d] %s\n", gettype($res), $res, mysqli_errno($link), mysqli_error($link));
}
if (!($res = mysqli_query($link, "SELECT id, label FROM test_mysqli_use_result_table_1 ORDER BY id"))) {
    printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
if (false !== ($tmp = mysqli_data_seek($res, 1))) {
    printf("[009] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
}
mysqli_close($link);
if (NULL !== ($tmp = mysqli_use_result($link))) {
    printf("[010] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
}
print "done!";
$test_table_name = 'test_mysqli_use_result_table_1';
require_once "clean_table.inc";
Example #29
0
/**
 * This function is the central function for handling database interaction.
 * The function can be used for setting up a database connection, for running
 * a SQL query and for returning query rows. Which of these actions the
 * function will handle and what the function return data will be, is
 * determined by the $return function parameter.
 *
 * @param $return   - What to return. Options are the following constants:
 *                    DB_RETURN_CONN      a db connection handle
 *                    DB_RETURN_QUOTED    a quoted parameter
 *                    DB_RETURN_RES       result resource handle
 *                    DB_RETURN_ROW       single row as array
 *                    DB_RETURN_ROWS      all rows as arrays
 *                    DB_RETURN_ASSOC     single row as associative array
 *                    DB_RETURN_ASSOCS    all rows as associative arrays
 *                    DB_RETURN_VALUE     single row, single column
 *                    DB_RETURN_ROWCOUNT  number of selected rows
 *                    DB_RETURN_NEWID     new row id for insert query
 *                    DB_RETURN_ERROR     an error message if the query
 *                                        failed or NULL if there was no error
 *                    DB_CLOSE_CONN       close the connection, no return data
 *
 * @param $sql      - The SQL query to run or the parameter to quote if
 *                    DB_RETURN_QUOTED is used.
 *
 * @param $keyfield - When returning an array of rows, the indexes are
 *                    numerical by default (0, 1, 2, etc.). However, if
 *                    the $keyfield parameter is set, then from each
 *                    row the $keyfield index is taken as the key for the
 *                    return array. This way, you can create a direct
 *                    mapping between some id field and its row in the
 *                    return data. Mind that there is no error checking
 *                    at all, so you have to make sure that you provide
 *                    a valid $keyfield here!
 *
 * @param $flags    - Special flags for modifying the function's behavior.
 *                    These flags can be OR'ed if multiple flags are needed.
 *                    DB_NOCONNECTOK     Failure to connect is not fatal but
 *                                       lets the call return FALSE (useful
 *                                       in combination with DB_RETURN_CONN).
 *                    DB_MISSINGTABLEOK  Missing table errors not fatal.
 *                    DB_DUPFIELDNAMEOK  Duplicate field errors not fatal.
 *                    DB_DUPKEYNAMEOK    Duplicate key name errors not fatal.
 *                    DB_DUPKEYOK        Duplicate key errors not fatal.
 *
 * @return $res     - The result of the query, based on the $return parameter.
 */
function phorum_db_interact($return, $sql = NULL, $keyfield = NULL, $flags = 0)
{
    static $conn;
    // Close the database connection.
    if ($return == DB_CLOSE_CONN) {
        if (!empty($conn)) {
            mysqli_close($conn);
            $conn = null;
        }
        return;
    }
    // Setup a database connection if no database connection is available yet.
    if (empty($conn)) {
        $PHORUM = $GLOBALS['PHORUM'];
        $conn = mysqli_connect($PHORUM['DBCONFIG']['server'], $PHORUM['DBCONFIG']['user'], $PHORUM['DBCONFIG']['password'], $PHORUM['DBCONFIG']['name'], $PHORUM['DBCONFIG']['port'], $PHORUM['DBCONFIG']['socket']);
        if ($conn === FALSE) {
            if ($flags & DB_NOCONNECTOK) {
                return FALSE;
            }
            phorum_database_error('Failed to connect to the database.');
            exit;
        }
        if (!empty($PHORUM['DBCONFIG']['charset'])) {
            mysqli_query($conn, "SET NAMES '{$PHORUM['DBCONFIG']['charset']}'");
        }
        // putting this here for testing mainly
        // All of Phorum should work in strict mode
        if (!empty($PHORUM["DBCONFIG"]["strict_mode"])) {
            mysqli_query($conn, "SET SESSION sql_mode='STRICT_ALL_TABLES'");
        }
    }
    // Return a quoted parameter.
    if ($return === DB_RETURN_QUOTED) {
        return mysqli_real_escape_string($conn, $sql);
    }
    // RETURN: database connection handle
    if ($return === DB_RETURN_CONN) {
        return $conn;
    }
    // By now, we really need a SQL query.
    if ($sql === NULL) {
        trigger_error('Internal error: phorum_db_interact(): ' . 'missing sql query statement!', E_USER_ERROR);
    }
    // Execute the SQL query.
    // For queries where we are going to retrieve multiple rows, we
    // use an unuffered query result.
    if ($return === DB_RETURN_ASSOCS || $return === DB_RETURN_ROWS) {
        $res = FALSE;
        if (mysqli_real_query($conn, $sql) !== FALSE) {
            $res = mysqli_use_result($conn);
        }
    } else {
        $res = mysqli_query($conn, $sql);
    }
    // Execute the SQL query.
    if ($res === FALSE) {
        // See if the $flags tell us to ignore the error.
        $ignore_error = FALSE;
        $errno = mysqli_errno($conn);
        switch ($errno) {
            // Table does not exist.
            case 1146:
                if ($flags & DB_MISSINGTABLEOK) {
                    $ignore_error = TRUE;
                }
                break;
                // Table already exists.
            // Table already exists.
            case 1050:
                if ($flags & DB_TABLEEXISTSOK) {
                    $ignore_error = TRUE;
                }
                break;
                // Duplicate column name.
            // Duplicate column name.
            case 1060:
                if ($flags & DB_DUPFIELDNAMEOK) {
                    $ignore_error = TRUE;
                }
                break;
                // Duplicate key name.
            // Duplicate key name.
            case 1061:
                if ($flags & DB_DUPKEYNAMEOK) {
                    $ignore_error = TRUE;
                }
                break;
                // Duplicate entry for key.
            // Duplicate entry for key.
            case 1062:
                // For MySQL server versions 5.1.15 up to 5.1.20.
                // See bug #28842 (http://bugs.mysql.com/bug.php?id=28842)
            // For MySQL server versions 5.1.15 up to 5.1.20.
            // See bug #28842 (http://bugs.mysql.com/bug.php?id=28842)
            case 1582:
                if ($flags & DB_DUPKEYOK) {
                    $ignore_error = TRUE;
                }
                break;
        }
        // Handle this error if it's not to be ignored.
        if (!$ignore_error) {
            $err = mysqli_error($conn);
            // RETURN: error message or NULL
            if ($return === DB_RETURN_ERROR) {
                return $err;
            }
            // Trigger an error.
            phorum_database_error("{$err} ({$errno}): {$sql}");
            exit;
        }
    }
    // RETURN: error message or NULL
    if ($return === DB_RETURN_ERROR) {
        return NULL;
    }
    // RETURN: query resource handle
    if ($return === DB_RETURN_RES) {
        return $res;
    } elseif ($return === DB_RETURN_ROWCOUNT) {
        return $res ? mysqli_num_rows($res) : 0;
    } elseif ($return === DB_RETURN_ROW || $return === DB_RETURN_ROWS || $return === DB_RETURN_VALUE) {
        // Keyfields are only valid for DB_RETURN_ROWS.
        if ($return !== DB_RETURN_ROWS) {
            $keyfield = NULL;
        }
        $rows = array();
        if ($res) {
            while ($row = mysqli_fetch_row($res)) {
                if ($keyfield === NULL) {
                    $rows[] = $row;
                } else {
                    $rows[$row[$keyfield]] = $row;
                }
            }
        }
        // Return all rows.
        if ($return === DB_RETURN_ROWS) {
            /* Might be FALSE in case of ignored errors. */
            if (!is_bool($res)) {
                mysqli_free_result($res);
            }
            return $rows;
        }
        // Return a single row.
        if ($return === DB_RETURN_ROW) {
            if (count($rows) == 0) {
                return NULL;
            } else {
                return $rows[0];
            }
        }
        // Return a single value.
        if (count($rows) == 0) {
            return NULL;
        } else {
            return $rows[0][0];
        }
    } elseif ($return === DB_RETURN_ASSOC || $return === DB_RETURN_ASSOCS) {
        // Keyfields are only valid for DB_RETURN_ASSOCS.
        if ($return !== DB_RETURN_ASSOCS) {
            $keyfield = NULL;
        }
        $rows = array();
        if ($res) {
            while ($row = mysqli_fetch_assoc($res)) {
                if ($keyfield === NULL) {
                    $rows[] = $row;
                } else {
                    $rows[$row[$keyfield]] = $row;
                }
            }
        }
        // Return all rows.
        if ($return === DB_RETURN_ASSOCS) {
            /* Might be FALSE in case of ignored errors. */
            if (!is_bool($res)) {
                mysqli_free_result($res);
            }
            return $rows;
        }
        // Return a single row.
        if ($return === DB_RETURN_ASSOC) {
            if (count($rows) == 0) {
                return NULL;
            } else {
                return $rows[0];
            }
        }
    } elseif ($return === DB_RETURN_NEWID) {
        return mysqli_insert_id($conn);
    }
    trigger_error('Internal error: phorum_db_interact(): ' . 'illegal return type specified!', E_USER_ERROR);
}
Example #30
-1
function mysqli_query_select_varchar_unbuffered($type, $len, $runs, $rows, $host, $user, $passwd, $db, $port, $socket, $flag_original_code)
{
    $errors = $times = array();
    foreach ($rows as $k => $num_rows) {
        foreach ($runs as $k => $run) {
            $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x overall'] = microtime(true);
            do {
                if (!($link = @mysqli_connect($host, $user, $passwd, $db, $port, $socket))) {
                    $errors[] = sprintf("%d rows: SELECT %s %dx connect failure (original code = %s)", $num_rows, $type, $run, $flag_original_code ? 'yes' : 'no');
                    break 3;
                }
                if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) {
                    $errors[] = sprintf("%d rows: SELECT %s %dx drop table failure (original code = %s): [%d] %s", $num_rows, $type, $run, $flag_original_code ? 'yes' : 'no', mysqli_errno($link), mysqli_error($link));
                    break 3;
                }
                if (!mysqli_query($link, sprintf("CREATE TABLE test(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, label %s)", $type))) {
                    $errors[] = sprintf("%d rows: SELECT %s %dx create table failure (original code = %s): [%d] %s", $num_rows, $type, $run, $flag_original_code ? 'yes' : 'no', mysqli_errno($link), mysqli_error($link));
                    break 3;
                }
                $label = '';
                for ($i = 0; $i < $len; $i++) {
                    $label .= chr(mt_rand(65, 90));
                }
                $label = mysqli_real_escape_string($link, $label);
                for ($i = 1; $i <= $num_rows; $i++) {
                    if (!mysqli_query($link, "INSERT INTO test(id, label) VALUES ({$i}, '{$label}')")) {
                        $errors[] = sprintf("%d rows: SELECT %s %dx insert failure (original code = %s): [%d] %s", $num_rows, $type, $run, $flag_original_code ? 'yes' : 'no', mysqli_errno($link), mysqli_error($link));
                        break 3;
                    }
                }
                for ($i = 0; $i < $run; $i++) {
                    $start = microtime(true);
                    mysqli_real_query($link, "SELECT id, label FROM test");
                    $res = mysqli_use_result($link);
                    $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x query()'] += microtime(true) - $start;
                    if (!$res) {
                        $errors[] = sprintf("%d rows: SELECT %s %dx insert failure (original code = %s): [%d] %s", $rows, $type, $run, $flag_original_code ? 'yes' : 'no', mysqli_errno($link), mysqli_error($link));
                        break 4;
                    }
                    $start = microtime(true);
                    while ($row = mysqli_fetch_assoc($res)) {
                    }
                    $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x fetch_assoc()'] += microtime(true) - $start;
                }
                mysqli_close($link);
            } while (false);
            $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x overall'] = microtime(true) - $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x overall'];
        }
    }
    return array($errors, $times);
}