本文整理汇总了PHP中mysqli_use_result函数的典型用法代码示例。如果您正苦于以下问题:PHP mysqli_use_result函数的具体用法?PHP mysqli_use_result怎么用?PHP mysqli_use_result使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mysqli_use_result函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _execute
/**
* 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;
}
示例2: cleanupExtraResults
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);
}
}
}
示例3: free_mysqli_results
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();
}
}
}
示例4: istable
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;
}
}
示例5: get_debug_info
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;
}
示例6: mysqli_query_select_varchar_unbuffered
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);
}
示例7: testMysqli
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;
}
示例8: domy
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;
}
示例9: printf
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";
示例10: rawUrlDecode
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 fucked 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..)
示例11: dbquery
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;
}
示例12: executeSP
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);
}
示例13: request2
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);
//.........这里部分代码省略.........
示例14: printf
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);
示例15: array
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!";