Example #1
9
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 />&nbsp;数组下标为{$i}的语句:{$arr_sqls[$i]}执行错误<br />&nbsp;错误原因:" . mysqli_error($link);
            return false;
        }
    } else {
        $error = '执行失败!请检查首条语句是否正确!<br />可能的错误原因:' . mysqli_error($link);
        return false;
    }
}
Example #2
0
 public function ResistMenuLog($_uid, $_log)
 {
     $query = "TRUNCATE TABLE UM" . $_uid . ";";
     $result = $this->_db_throw_query("Users_Geo", $query);
     $query = "";
     $tmp = "INSERT INTO UM" . $_uid . " VALUES ( '";
     for ($i = 0; $i < 7; $i++) {
         for ($j = 0; $j < 3; $j++) {
             if ($j == 2) {
                 if (strpos($_log[$this->week[$i]][$this->kind[$j]], '|') !== false) {
                     $div = explode('|', $_log[$this->week[$i]][$this->kind[$j]]);
                     $size = count($div);
                     for ($k = 0; $k < $size; $k++) {
                         $query = $query . $tmp . $div[$k] . "', '" . $this->kind[$j] . "', ( NOW() + INTERVAL " . $i . " DAY ) );";
                     }
                     break;
                 }
             }
             $query = $query . $tmp . $_log[$this->week[$i]][$this->kind[$j]] . "', '" . $this->kind[$j] . "', ( NOW() + INTERVAL " . $i . " DAY ) );";
         }
     }
     $this->_db_select("Users_Geo");
     $result = mysqli_multi_query($this->_connection, $query);
     if (!$result) {
         print "Quely Failed.\n" . mysqli_error($this->_connection);
         return false;
     }
     do {
         mysqli_store_result($this->_connection);
     } while (mysqli_next_result($this->_connection));
     return true;
 }
Example #3
0
 public function multi_query($sql = "")
 {
     $this->last_query = $sql;
     $result = mysqli_multi_query($this->connection, $sql);
     $this->confirm_query($result);
     return $result;
 }
Example #4
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));
     }
 }
 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));
 }
Example #6
0
 public function multiQuery()
 {
     //          file_put_contents("db-sql.log", implode(";", $this->queries) . "\n", FILE_APPEND);
     $success = mysqli_multi_query($this->db, implode(";", $this->queries));
     $this->clearMultiQuery();
     return $success;
 }
Example #7
0
function sqllogin($host, $dbuser, $dbpass, $dbname)
{
    // connectivity
    //mysql connections for stacked query examples.
    $con1 = mysqli_connect($host, $dbuser, $dbpass, $dbname);
    $username = mysqli_real_escape_string($con1, $_POST["login_user"]);
    $password = $_POST["login_password"];
    // Check connection
    if (mysqli_connect_errno($con1)) {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    } else {
        @mysqli_select_db($con1, $dbname) or die("Unable to connect to the database ######: ");
    }
    /* execute multi query */
    $sql = "SELECT * FROM users WHERE username='******' and password='******'";
    if (@mysqli_multi_query($con1, $sql)) {
        /* store first result set */
        if ($result = @mysqli_store_result($con1)) {
            if ($row = @mysqli_fetch_row($result)) {
                if ($row[1]) {
                    return $row[1];
                } else {
                    return 0;
                }
            }
        }
    }
}
Example #8
0
 function execSP($sql)
 {
     $this->connMySQL();
     $this->sql = $sql;
     $i = 0;
     $result_ = null;
     if (mysqli_multi_query($this->conn, $this->sql)) {
         do {
             if ($this->resultado = mysqli_store_result($this->conn)) {
                 while ($row = mysqli_fetch_array($this->resultado)) {
                     $result_ = $row;
                 }
                 mysqli_free_result($this->resultado);
             }
             $i++;
         } while (mysqli_next_result($this->conn));
         mysqli_close($this->conn);
     } else {
         echo mysqli_error($this->conn);
         $this->closeConnMySQL();
         exit;
     }
     $this->closeConnMySQL();
     return $result_;
 }
 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 db_query($query)
 {
     while ($this->db_fetch_next_result()) {
     }
     if (!@mysqli_multi_query($this->link, $query)) {
         $this->errnum = mysqli_errno($this->link);
         $this->error = mysqli_error($this->link);
         $this->error_flag = 1;
         return false;
     }
     $this->result = mysqli_store_result($this->link);
     if (!$this->result) {
         $this->errnum = mysqli_errno($this->link);
         $this->error = mysqli_error($this->link);
         $this->error_flag = 1;
         return false;
     }
     $this->num_fields = @mysqli_num_fields($this->result);
     if ($this->num_fields) {
         $this->num_rows = @mysqli_num_rows($this->result);
     } else {
         $this->num_rows = @mysqli_affected_rows($this->link);
         $this->num_fields = 0;
     }
     return true;
 }
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;
}
Example #12
0
 public function use_sql_string()
 {
     $sql = read_file($this->sql_path);
     $sql = trim($sql);
     $sql = $this->db->_prep_query($sql);
     $link = @mysqli_connect($this->db->hostname, $this->db->username, $this->db->password, $this->db->database);
     mysqli_multi_query($link, $sql);
 }
Example #13
0
 private function importDb($data)
 {
     $sql = file_get_contents('install.sql');
     $link = mysqli_connect($data['host'], $data['user'], $data['pass'], $data['dbname']);
     @mysqli_multi_query($link, $sql);
     $this->response['result'] = true;
     $this->deleteFolderInstall();
 }
Example #14
0
 static function update_repeat_prop_qualifier($eid, $prop_group_id, $prop_id, $ron, $prop_qual_id)
 {
     $sql = sprintf("Call update_repeat_prop_qualifier(%s,%s,%s,%s,%s)", $eid, $prop_group_id, $prop_id, $ron, $prop_qual_id);
     if (!mysqli_multi_query($_SESSION['mysqli_link'], $sql)) {
         echo "<div style='z-index:1500'>ERROR! (UpdaterSprocsContainer:aasarek)" . mysqli_error($_SESSION['mysqli_link']) . "</div>";
     }
     //$result = mysqli_store_result($_SESSION['mysqli_link']); echo "store result::" .mysqli_error($_SESSION['mysqli_link']);
     //mysqli_free_result($result); echo $sql;
 }
Example #15
0
 public static function fnc($f, $p)
 {
     if (self::$msql == NULL) {
         self::$msql = mysqli_connect(self::$host, self::$user, self::$pass, self::$base);
         mysqli_query(self::$msql, 'SET NAMES UTF8');
     }
     mysqli_multi_query(self::$msql, "CALL {$f}({$p})");
     $result = mysqli_store_result(self::$msql);
     $r = self::fetch_r($result);
     return $r;
 }
Example #16
0
 /**
  * @brief		Méthode d'execution de requetes
  * @details		Execute la requette 
  *				DB_HOST, DB_USER, DB_PASSWORD
  *				Le pointeur de la requete est renvoyé et stocké au niveau du singleton
  * @return	query_result	Renvoie le resultat de la requette a fetcher
  */
 public static function multiQuery($query, $connect_handler = NULL)
 {
     if ($connect_handler == null) {
         if (self::$connect_handler == null) {
             self::connect();
         }
         self::$query_result = mysqli_multi_query(self::$connect_handler, $query);
     } else {
         self::$query_result = mysqli_multi_query($connect_handler, $query);
     }
     return self::$query_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;
}
Example #18
0
function deleteList($list)
{
    if ($connexion = mysqli_connect('localhost', 'root', '', 'samirello')) {
        $requete = "DELETE FROM lists WHERE `listname`='{$list}'; ";
        //  $requete = "DELETE FROM users WHERE `listname`='$list' ";
        $requete .= "DELETE FROM users WHERE `listname`='{$list}' ";
        $resultat = mysqli_multi_query($connexion, $requete);
        echo "resultat : " . ($resultat ? 'deleted' : 'error');
    } else {
        echo "erreur BDD !";
    }
}
Example #19
0
function addLink()
{
    global $db_link;
    $title = $_POST["title"];
    $link = $_POST["link"];
    $category = $_POST["category"];
    $sql = sprintf("SET @pri = (SELECT priority FROM List_item WHERE category = '%s' ORDER BY priority DESC LIMIT 1) + 1; " . "INSERT INTO List_item(title, link, category, priority) " . "VALUES ('%s', '%s', '%s', @pri);", $category, $title, $link, $category);
    if (mysqli_multi_query($db_link, $sql)) {
        header("Location: edit.php");
    } else {
        echo "Error in query '{$sql}': " . mysqli_error($db_link);
    }
}
Example #20
0
function executeQueryFile($dbuser, $dbpass, $dbname, $dbhost)
{
    global $path;
    $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
    if (mysqli_connect_error()) {
        die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
    }
    $sql = file_get_contents($path . "/libs/db.sql");
    if (!$sql) {
        die('Error opening file');
    }
    mysqli_multi_query($mysqli, $sql);
    $mysqli->close();
}
Example #21
0
 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;
 }
Example #22
0
 public function GetMultiResults($SqlCommand)
 {
     /* execute multi query */
     if (mysqli_multi_query($this->mysqli, $SqlCommand)) {
         $i = 0;
         do {
             if ($result = $this->mysqli->store_result()) {
                 while ($row = $result->fetch_assoc()) {
                     $this->Data[$i][] = $row;
                 }
                 mysqli_free_result($result);
             }
             $i++;
         } while ($this->mysqli->next_result());
     }
     return $this->Data;
 }
Example #23
0
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);
    }
}
Example #24
0
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;
}
Example #25
0
 function multi_query($queryString, $params = NULL)
 {
     $queryString = isset($params) ? str_format($queryString, $params) : $queryString;
     $outputArray = array();
     if (mysqli_multi_query($this->connection, $queryString)) {
         do {
             if ($queryResult = mysqli_store_result($this->connection)) {
                 $array = array();
                 while ($row = mysqli_fetch_assoc($queryResult)) {
                     $array[] = $row;
                 }
                 $outputArray[] = $array;
                 mysqli_free_result($queryResult);
             }
         } while (mysqli_next_result($this->connection));
         return $outputArray;
     }
     return FALSE;
 }
Example #26
0
 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;
     }
 }
Example #27
0
 /**
  * This function create the database if needed and executing the dump file if needed
  */
 public function createDB()
 {
     // Try to connect to the DB.
     // If we got to this point the connection should fail
     // First of all try to connect to the mySQL server.
     // First of all try to connect to the mySQL server.
     $conn = mysql_connect($_POST['hostname'], $_POST['username'], $_POST['password']);
     if (!$conn) {
         $_REQUEST['error'] = 'mySQL is not running or maybe<br/>wrong username / password';
         return;
     }
     // Check to see if the requested database exist
     if (!mysql_select_db($_POST['database'], $conn)) {
         // Create the databse
         if (!mysql_query('CREATE DATABASE ' . $_POST['database'], $conn)) {
             $_REQUEST['error'] = "Error creating database: " . mysql_error();
             return;
         }
         mysql_close($conn);
         // From this point i switched driver since this was the only way i was able to
         // execute dump file anf not a single SQL query.
         $conn = new \mysqli($_POST['hostname'], $_POST['username'], $_POST['password'], $_POST['database']);
         if (mysqli_connect_error()) {
             $_REQUEST['error']('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
             return;
         }
         $sql = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/db/dump.sql');
         if (!$sql) {
             $_REQUEST['error'] = 'Error opening file: ' . $_SERVER['DOCUMENT_ROOT'] . '/db/dump.sql';
             return;
         }
         // Execute the dump script
         if (!mysqli_multi_query($conn, $sql)) {
             $_REQUEST['error'] = 'Error while executing dump file: ' . $_SERVER['DOCUMENT_ROOT'] . '/db/dump.sql';
             return;
         }
         // Database was successfully created.
         // Redirect to login page.
         $conn->close();
     }
     header('Location: /views/user/login.php');
 }
 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;
 }
function editEmployee($conn, $empAndTraits)
{
    $query = "UPDATE  `test_two`.`employee_info`" . " SET `first_name`='{$empAndTraits['firstName']}'," . "`last_name` = '{$empAndTraits['lastName']}'," . "`phone_number` = '{$empAndTraits['phoneNumber']}'," . "`address`='{$empAndTraits['address']}'," . "`age`='{$empAndTraits['age']}'" . "WHERE `idemployee_info` = '{$empAndTraits['idToEdit']}';";
    $query .= "UPDATE  `test_two`.`traits`" . " SET `hair_color`='{$empAndTraits['hairColor']}'," . "`eye_color` = '{$empAndTraits['eyeColor']}'," . "`weight` = '{$empAndTraits['weight']}'," . "`height`='{$empAndTraits['height']}'" . "WHERE `employee_id` = '{$empAndTraits['idToEdit']}';";
    if ($is_successful = mysqli_multi_query($conn, $query)) {
        do {
            if ($result = mysqli_store_result($conn)) {
                my_sqli_free_result($result);
            }
        } while (mysqli_next_result($conn));
    }
    if ($is_successful) {
        return showAllrows($conn);
    } else {
        return 'ERROR';
    }
}
Example #30
-8
function fn_execSQL($sql, $r = 0)
{
    global $conexao;
    if (mysqli_multi_query($conexao, $sql)) {
        $resultado = mysqli_store_result($conexao);
        if ($resultado) {
            //prepara um array com os campos/colunas da consulta
            $i = 0;
            while ($obj = mysqli_fetch_field($resultado)) {
                $arrayCampos[$i] = $obj->name;
                $i++;
            }
            //prepara um array associativo com o resultado da consulta
            $i = 0;
            while ($linha = mysqli_fetch_array($resultado)) {
                for ($j = 0; $j < count($arrayCampos); $j++) {
                    $retorno[$i][$arrayCampos[$j]] = $linha[$arrayCampos[$j]];
                }
                $i++;
            }
            mysqli_free_result($resultado);
        }
        //mysqli_close($conexao_geral);
        if (isset($retorno)) {
            return $retorno;
        } else {
            return null;
        }
    } else {
        echo "<p>N�o foi poss�vel executar a seguinte instru��o SQL:</p><p><strong>{$sql}</strong></p>\n" . "<p>Erro MySQL: " . mysqli_error($conexao) . "</p>";
        exit;
        //mysqli_close($conexao_geral);
    }
}