function execute_multi($link, $arr_sqls, &$error) { $sqls = implode(';', $arr_sqls) . ';'; if (mysqli_multi_query($link, $sqls)) { $data = array(); $i = 0; //计数 do { if ($result = mysqli_store_result($link)) { $data[$i] = mysqli_fetch_all($result); mysqli_free_result($result); } else { $data[$i] = null; } $i++; if (!mysqli_more_results($link)) { break; } } while (mysqli_next_result($link)); if ($i == count($arr_sqls)) { return $data; } else { $error = "sql语句执行失败:<br /> 数组下标为{$i}的语句:{$arr_sqls[$i]}执行错误<br /> 错误原因:" . mysqli_error($link); return false; } } else { $error = '执行失败!请检查首条语句是否正确!<br />可能的错误原因:' . mysqli_error($link); return false; } }
function clone_db($database_name = false, $organization_id = false) { $qry = $this->db->query('CREATE DATABASE ' . $database_name); if (!$qry) { $value = array('code' => '500', 'organization_id' => $organization_id); $json_data = json_encode($value); redirect('http://junctiondev.cloudapp.net/appmanager/login/result_application?json=' . $json_data); } $this->session->set_userdata('db_name', $database_name); $this->session->userdata('db_name'); if ($_SERVER['HTTP_HOST'] == "localhost") { //$dbname=$database_name; $password = ""; $username = "******"; } if ($_SERVER['HTTP_HOST'] == "junctiondev.cloudapp.net") { //$dbname=$database_name; $password = "******"; $username = "******"; } if ($_SERVER['HTTP_HOST'] == "junctiontech.in") { //$dbname=$database_name; $password = "******"; $username = "******"; } $connect = mysqli_connect('localhost', $username, $password, $database_name); $db_file = file_get_contents('junctionerp.sql'); mysqli_multi_query($connect, $db_file); do { mysqli_store_result($connect); } while (mysqli_more_results($connect) && mysqli_next_result($connect)); return true; }
function cloneDB($database_name = false) { $this->db->query('CREATE DATABASE ' . $database_name); if ($_SERVER['HTTP_HOST'] == "localhost") { //$dbname=$database_name; $password = ""; $username = "******"; } if ($_SERVER['HTTP_HOST'] == "junctiondev.cloudapp.net") { //$dbname=$database_name; $password = "******"; $username = "******"; } if ($_SERVER['HTTP_HOST'] == "junctiontech.in") { //$dbname=$database_name; $password = "******"; $username = "******"; } $connect = mysqli_connect('localhost', $username, $password, $database_name); $db_file = file_get_contents('school_mgt.sql'); mysqli_multi_query($connect, $db_file); do { mysqli_store_result($connect); } while (mysqli_more_results($connect) && mysqli_next_result($connect)); }
function task_optimize($connection, $settings, $time, $table = false, $and_default = true) { require_once $settings['functions'] . 'function.task.log.php'; if ($table) { $tables[] = $table; } if ($and_default) { $tables[] = 'peers'; $tables[] = 'tasks'; $tables[] = 'torrents'; } $sql = ''; foreach ($tables as $table) { $sql .= 'CHECK TABLE `' . $settings['db_prefix'] . $table . '`;' . 'ANALYZE TABLE `' . $settings['db_prefix'] . $table . '`;' . 'REPAIR TABLE `' . $settings['db_prefix'] . $table . '`;' . 'OPTIMIZE TABLE `' . $settings['db_prefix'] . $table . '`;'; } $result = mysqli_multi_query($connection, $sql); if ($result) { while (mysqli_more_results($connection)) { mysqli_next_result($connection); mysqli_store_result($connection); } } if ($result) { task_log($connection, $settings, 'optimize', $time); } return $result; }
function callStoredProcedure($procedure) { global $link; // if (DEBUGGING) { echo "CALL ".$procedure ."<BR>";} $resultset = mysqli_multi_query($link, "CALL " . $procedure) or die(__FILE__ . __LINE__ . mysqli_error($link) . $procedure); $data = mysqli_store_result($link); // clear remaining sets in the resultset before returning while (mysqli_more_results($link)) { mysqli_next_result($link); } return $data; }
public function query($SQL) { if ($SQL !== "") { if (stristr($SQL, "call") and stripos($SQL, "call") === 0) { mysqli_multi_query(self::$connection, $SQL); $this->query = mysqli_store_result(self::$connection); if (mysqli_more_results(self::$connection)) { mysqli_next_result(self::$connection); } } else { $this->query = mysqli_query(self::$connection, $SQL); } } return $this->query ? $this->query : false; }
/** * Send an SQL Query to the DB * * @param string $query * @return mysql_result */ public function Query($query) { try { if (!$this->connection) { throw new ErrorException(); } $result = mysqli_query($this->connection, $query); while (mysqli_more_results($this->connection)) { mysqli_next_result($this->connection); } return $result; } catch (ErrorException $obj) { @error_log($query . $this->errorString); } //end try }
/** * Free memory associated with the resultset * * @return void */ public function flush() { if ($this->result instanceof mysqli_stmt) { $this->result->free_result(); } $this->result = null; $this->col_info = null; // Sanity check before using the handle if (empty($this->dbh) || !$this->dbh instanceof mysqli) { return; } // Clear out any results from a multi-query while (mysqli_more_results($this->dbh)) { mysqli_next_result($this->dbh); } }
function executeQuery($query, $host, $user, $pass, $db, $port, $link = null) { if (!$link && !connect($link, $host, $user, $pass, $db, $port)) { return false; } else { if (isset($db) && !mysqli_select_db($link, $db)) { return false; } } if (!mysqli_multi_query($link, $query) || $link->error != '') { return false; } while (mysqli_more_results($link) && mysqli_next_result($link)) { $discard = mysqli_store_result($link); } $link->commit(); return true; }
function sql($string) { global $db; global $result; if (trim($string) === '') { return; } mysqli_multi_query($db, $string) or die("MySQL Error when executing: {$string} <br/>\n" . mysqli_error($db) . "\n"); $test = true; while (mysqli_more_results($db)) { $test = false; $result = mysqli_store_result($db); mysqli_next_result($db) or die("MySQL Error when executing: {$string} <br/>\n" . mysqli_error($db) . "\n"); } if ($test) { $result = mysqli_store_result($db); } }
function clone_db($database_name = false) { //echo $database_name; return; $this->db->query('CREATE DATABASE ' . $database_name); if ($_SERVER['HTTP_HOST'] == "localhost") { //$dbname=$database_name; $password = ""; $username = "******"; } if ($_SERVER['HTTP_HOST'] == "junctiondev.cloudapp.net") { //$dbname=$database_name; $password = "******"; $username = "******"; } if ($_SERVER['HTTP_HOST'] == "junctiontech.in") { //$dbname=$database_name; $password = "******"; $username = "******"; } $connect = mysqli_connect('localhost', $username, $password, $database_name); $db_file = file_get_contents('school_mgt.sql'); mysqli_multi_query($connect, $db_file); do { mysqli_store_result($connect); } while (mysqli_more_results($connect) && mysqli_next_result($connect)); $query = "SELECT count(*) as 'Tables', table_schema as 'Database' FROM information_schema.TABLES WHERE table_schema= '" . $database_name . "' GROUP BY table_schema"; $result = mysqli_query($connect, $query); $countTable = mysqli_fetch_assoc($result); //echo $countTable['Tables'];die; if (isset($countTable['Tables']) && $countTable['Tables'] == '76') { return true; } else { //$CII =& get_instance(); // $CII->load->library('session'); //if it's not autoloaded in your CI setup // $database_name=$CII->session->userdata('db_name'); // $CII->session->unset_userdata($database_name); // $CII->session->sess_destroy(); echo 'database does not exist'; return; die; } }
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; }
protected function exec($qs) { if (null == $this->conn) { return false; } $status = true; foreach ($qs as $q) { $res = @mysqli_query($this->conn, $q); if (false == $res) { $this->session->addError(@mysqli_error($this->conn)); $status = false; continue; } if (@mysqli_more_results($this->conn)) { @mysqli_next_result($this->conn); @mysqli_free_result($res); } } return $status; }
/** * Execute a mySQL query or multi queries * @param string $query mySQL query, or multiple queries seperated by a ';' * @param array $db_params db parameters array 'db_host', 'db_user', 'db_pass', 'db_port' * @param string $db_name database name * @param mysqli $link mysqli link * @return true on success, false otherwise */ public static function executeQuery($query, $db_params, $db_name, $link = null) { // connect if not yet connected if (!$link && !self::connect($link, $db_params, $db_name)) { return false; } else { if (isset($db_name) && !mysqli_select_db($link, $db_name)) { logMessage(L_ERROR, "Cannot execute query: could not find the db: {$db}"); return false; } } // execute all queries if (!mysqli_multi_query($link, $query) || $link->error != '') { logMessage(L_ERROR, "Cannot execute query: error with query: {$query}, error: " . $link->error); return false; } // flush while (mysqli_more_results($link) && mysqli_next_result($link)) { $discard = mysqli_store_result($link); } $link->commit(); return true; }
function func_test_mysqli_next_result($link, $query, $offset, $num_results, $strict_on) { if (!mysqli_multi_query($link, $query)) { printf("[%03d] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link)); } $i = 0; if ($strict_on) { ob_start(); } do { if ($res = mysqli_store_result($link)) { mysqli_free_result($res); $i++; } } while (true === 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("[%03d] Strict Standards warning missing\n", $offset + 1); } else { $tmp = trim(preg_replace('@Strict Standards: mysqli_next_result\\(\\).*on line \\d+@ism', '', $tmp)); } print trim($tmp) . "\n"; } if ($i !== $num_results) { printf("[%03d] Expecting %d result(s), got %d result(s)\n", $offset + 2, $num_results, $i); } if (mysqli_more_results($link)) { printf("[%03d] mysqli_more_results() indicates more results than expected\n", $offset + 3); } if (!($res = mysqli_query($link, "SELECT 1 AS b"))) { printf("[%03d] [%d] %s\n", $offset + 4, mysqli_errno($link), mysqli_error($link)); } else { mysqli_free_result($res); } }
/** * Clean up link to database. Any received results over this link will be lost. * You MUST call this function after each stored procedure call. * @param MySQLi $link Link to database. */ function db_cleanup_link($link) { /* * Если использовать mysqli_use_result вместо store, то * не будет выведена ошибка, если таковая произошла в следующем запросе * в mysqli_multi_query. */ if (($result = mysqli_store_result($link)) != false) { mysqli_free_result($result); } $loop = 0; while (mysqli_more_results($link) && ++$loop < 1000) { mysqli_next_result($link); if (($result = mysqli_store_result($link)) != false) { mysqli_free_result($result); } } if ($loop >= 1000) { throw new ParanoicException('Probably infinity loop.'); } if (mysqli_errno($link)) { throw new DBException(mysqli_error($link)); } }
/** * 清空多余结果集 * @return void * @since 1.0.0 */ private function clear_more_result() { while (mysqli_more_results($this->conn)) { mysqli_next_result($this->conn); if ($rs = mysqli_store_result($this->conn)) { mysqli_free_result($rs); } } }
/** * Move the internal result pointer to the next available result * * @param a valid result resource * @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_store_result($connection))) { return false; } return MDB2_OK; }
/** * Check if there are any more query results from a multi query * * @param mysqli $link the mysqli object * * @return bool true or false */ public function moreResults($link) { return mysqli_more_results($link); }
/** * Check if there are any more query results from a multi query * * @param mysqli $link the mysqli object * * @return bool true or false */ function PMA_DBI_more_results($link = null) { if (empty($link)) { if (isset($GLOBALS['userlink'])) { $link = $GLOBALS['userlink']; } else { return false; } } return mysqli_more_results($link); }
/** * Frees the current result if one exists and returns the next result from a multi query. * @return mysqli_result The next result from a MySQL multi query */ public function nextResult() { if ($this->m_result) { mysqli_free_result($this->m_result); } if (mysqli_more_results($this->m_link)) { mysqli_next_result($this->m_link); if ($this->m_result = mysqli_store_result($this->m_link)) { return $this->m_result; } else { return false; } } else { return false; } }
/** * Call stored procedure * * @param string $spname Store procedure name * @param array $params Array of params * @return array * @todo Normalize and sanitize params. Need to search in the ADODB code. */ function Call($spname, $inparams = "", $outparams = "") { $escaped_params = ""; if ($inparams != '') { $escaped_params = array(); foreach ((array) $inparams as $v) { if ($v != '') { $escaped_params[] = $this->qstr($v, get_magic_quotes_gpc()); } else { $escaped_params[] = "''"; } } } if ($outparams != '') { foreach ($outparams as $oparam) { $var_create_sql .= "SET @{$oparam['name']} := {$oparam['defval']};"; $sp_outparams[] = "@{$oparam['name']}"; } } // Prepare call SQL $params_string = is_array($escaped_params) ? implode(",", $escaped_params) : $escaped_params; $params_string .= is_array($sp_outparams) ? "," . implode(",", $sp_outparams) : ""; $sql = "{$var_create_sql}call {$spname}({$params_string})"; $retval = false; if (mysqli_multi_query($this->_connectionID, $sql)) { $i = 0; $retval = array(); // Iterate trough results do { if ($result = mysqli_store_result($this->_connectionID)) { while ($row = mysqli_fetch_assoc($result)) { $retval[$i] = $row; } $result->close(); } if (mysqli_more_results($this->_connectionID)) { $i++; } } while (mysqli_next_result($this->_connectionID)); } else { if ($this->debug) { ADOConnection::outp("Stored procedure call: " . $sql . " failed. " . $this->ErrorMsg()); } } // In case if we have just one result, lets make simplify array if ($i == 1) { $retval = $retval[0]; } return $retval; }
/* execute multi query */ if (mysqli_multi_query($con1, $sql)) { /* store first result set */ if ($result = mysqli_store_result($con1)) { if ($row = mysqli_fetch_row($result)) { echo '<font size = "5" color= "#00FF00">'; printf("Your Username is : %s", $row[1]); echo "<br>"; printf("Your Password is : %s", $row[2]); echo "<br>"; echo "</font>"; } // mysqli_free_result($result); } /* print divider */ if (mysqli_more_results($con1)) { //printf("-----------------\n"); } //while (mysqli_next_result($con1)); } /* close connection */ mysqli_close($con1); } else { echo "Please input the ID as parameter with numeric value"; } ?> </font> </div></br></br></br><center> <img src="../images/Less-41.jpg" /></center> </body> </html>
function _close() { //if results are attached to this pointer from Stored Proceedure calls, the next standard query will die 2014 //only a problem with persistant connections while (mysqli_more_results($this->connection->_connectionID)) { @mysqli_next_result($this->connection->_connectionID); } mysqli_free_result($this->_queryID); $this->_queryID = false; }
$resultArray = array(); do { /* store first result set */ if ($result = mysqli_store_result($con)) { while ($row = mysqli_fetch_row($result)) { foreach ($files1 as $value) { if (strpos("." . strtolower($value), str_replace("@bu.edu", "", strtolower($row[4]))) !== FALSE) { $row[4] = $value; break; } } $resultArray[] = $row; } mysqli_free_result($result); } if (!mysqli_more_results($con)) { break; } } while (mysqli_next_result($con)); mysqli_close($con); ?> <body> <table class="content"> <tr> <td> <h1 class="name"></h1> <h2 class="details"></h2> <img class="picture" style="max-height: 60vh; margin-top: 20px;"> <h4 class="count" style="margin-top: 20px"></h4> </td><td>
if (!mysqli_query($link, 'DROP PROCEDURE IF EXISTS p')) { printf("[003] [%d] %s.\n", mysqli_errno($link), mysqli_error($link)); } if (mysqli_real_query($link, 'CREATE PROCEDURE p(IN ver_in VARCHAR(25), OUT ver_out VARCHAR(25)) BEGIN SELECT ver_in INTO ver_out; END;')) { if (!($stmt = mysqli_prepare($link, 'CALL p(?, ?)'))) { printf("[005] Cannot prepare CALL, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } $ver_in = 'myversion'; $ver_out = ''; if (!mysqli_stmt_bind_param($stmt, 'ss', $ver_in, $ver_out)) { printf("[006] Cannot bind parameter, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); } if (!mysqli_stmt_execute($stmt)) { printf("[007] Cannot execute CALL, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); } printf("[008] More results: %s\n", mysqli_more_results($link) ? "yes" : "no"); printf("[009] Next results: %s\n", mysqli_next_result($link) ? "yes" : "no"); if (!mysqli_stmt_bind_result($stmt, $ver_out) || !mysqli_stmt_fetch($stmt)) { printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); } if ("myversion" !== $ver_out) { printf("[011] Results seem wrong got '%s'\n", $ver_out); } if (!mysqli_stmt_close($stmt)) { printf("[012] Cannot close statement, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); } if (!($res = $link->query("SELECT 1"))) { printf("[013] [%d] %s\n", $link->errno, $link->error); } } else { printf("[004] Cannot create SP, [%d] %s.\n", mysqli_errno($link), mysqli_error($link));
public function more_result() { return mysqli_more_results($this->db_connect_id); }
/** * Kill cached query results. * * @since 0.71 */ public function flush() { $this->last_result = array(); $this->col_info = null; $this->last_query = null; $this->rows_affected = $this->num_rows = 0; $this->last_error = ''; if ($this->use_mysqli && $this->result instanceof mysqli_result) { mysqli_free_result($this->result); $this->result = null; // Sanity check before using the handle if (empty($this->dbh) || !$this->dbh instanceof mysqli) { return; } // Clear out any results from a multi-query while (mysqli_more_results($this->dbh)) { mysqli_next_result($this->dbh); } } elseif (is_resource($this->result)) { mysql_free_result($this->result); } }
/** * Executes given SQL statement (procedure call). * * @param string $sql SQL statement (procedure call) * @return resource Result resource identifier for first recordset * @access protected */ function _executeProcedure($sql) { $answer = mysqli_multi_query($this->connection, $sql); $firstResult = mysqli_store_result($this->connection); if (mysqli_more_results($this->connection)) { while ($lastResult = mysqli_next_result($this->connection)) { } } return $firstResult; }
public function queries($sql) { try { @mysqli_multi_query($this->db, $sql); do { if ($result = @mysqli_store_result($this->db)) { mysqli_free_result($result); } if (mysqli_error($this->db)) { throw new ServiceException("INVALID_CONFIGURATION", "Error executing queries (" . (strlen($sql) > 40 ? substr($sql, 0, 40) . "..." : $sql) . "): " . mysqli_error($this->db)); } if (!mysqli_more_results($this->db)) { break; } mysqli_next_result($this->db); } while (TRUE); } catch (mysqli_sql_exception $e) { if (Logging::isDebug()) { Logging::logDebug("ERROR: " . $e); } throw new ServiceException("INVALID_CONFIGURATION", "Error executing queries (" . (strlen($sql) > 40 ? substr($sql, 0, 40) . "..." : $sql) . "...): " . mysqli_error($this->db)); } }