本文整理汇总了PHP中mysqli_use_result函数的典型用法代码示例。如果您正苦于以下问题:PHP mysqli_use_result函数的具体用法?PHP mysqli_use_result怎么用?PHP mysqli_use_result使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mysqli_use_result函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:ocpyosep78,项目名称:Office-Project-Management,代码行数:23,代码来源:mysqli_driver.php
示例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);
}
}
}
开发者ID:mirshko,项目名称:schedulemaker,代码行数:10,代码来源:processDump.php
示例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();
}
}
}
开发者ID:awgtek,项目名称:myedb,代码行数:10,代码来源:commonfunc.php
示例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;
}
}
开发者ID:KunalT6569,项目名称:opinion-mining,代码行数:11,代码来源:mfunctions.php
示例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;
}
开发者ID:BackupTheBerlios,项目名称:qsf-svn,代码行数:11,代码来源:mysqli.php
示例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);
}
开发者ID:splitice,项目名称:mysqlnd_ms,代码行数:51,代码来源:mysqli_sel_unbuf.php
示例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;
}
开发者ID:muzammalali,项目名称:php-mysql-access-test,代码行数:20,代码来源:mysql.php
示例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;
}
开发者ID:ZeitZumSterben,项目名称:website-cms,代码行数:21,代码来源:mysql.php
示例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";
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:mysqli_result_references.php
示例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..)
开发者ID:horatiu665,项目名称:tweetlistenerweb,代码行数:31,代码来源:customQuery.php
示例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;
}
开发者ID:clamiax,项目名称:bored,代码行数:66,代码来源:bored.php
示例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);
}
开发者ID:sergrin,项目名称:crawlers-il,代码行数:63,代码来源:DBAdapter2.class.php
示例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);
//.........这里部分代码省略.........
开发者ID:sawh,项目名称:ostepu-system,代码行数:101,代码来源:DBRequest.php
示例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);
开发者ID:gleamingthecube,项目名称:php,代码行数:31,代码来源:ext_mysqli_tests_mysqli_real_query.php
示例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!";
开发者ID:gleamingthecube,项目名称:php,代码行数:31,代码来源:ext_mysqli_tests_mysqli_result_references_mysqlnd.php
示例16: call
/**
* 调用存储过程
*
* @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;
}
开发者ID:pbchen,项目名称:thirdLoginAPI,代码行数:18,代码来源:Db.php
示例17: mysql_unbuffered_query
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;
}
开发者ID:gsomoza,项目名称:php7-mysql-shim,代码行数:8,代码来源:mysql.php
示例18: nextResult
/**
* 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;
}
开发者ID:ajisantoso,项目名称:kateglo,代码行数:23,代码来源:mysqli.php
示例19: interact
//.........这里部分代码省略.........
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;
开发者ID:samuell,项目名称:Core,代码行数:67,代码来源:mysqli.php
示例20: phorum_db_interact
/**
* 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);
//.........这里部分代码省略.........
开发者ID:sheldon,项目名称:dejavu,代码行数:101,代码来源:mysqli.php
注:本文中的mysqli_use_result函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论