/**
  * Do NOT use in code, to be used by database_manager only!
  * @param string|array $sql query
  * @param array|null $tablenames an array of xmldb table names affected by this request.
  * @return bool true
  * @throws ddl_change_structure_exception A DDL specific exception is thrown for any errors.
  */
 public function change_database_structure($sql, $tablenames = null)
 {
     $this->get_manager();
     // Includes DDL exceptions classes ;-)
     if (is_array($sql)) {
         $sql = implode("\n;\n", $sql);
     }
     try {
         $this->query_start($sql, null, SQL_QUERY_STRUCTURE);
         $result = $this->mysqli->multi_query($sql);
         if ($result === false) {
             $this->query_end(false);
         }
         while ($this->mysqli->more_results()) {
             $result = $this->mysqli->next_result();
             if ($result === false) {
                 $this->query_end(false);
             }
         }
         $this->query_end(true);
     } catch (ddl_change_structure_exception $e) {
         while (@$this->mysqli->more_results()) {
             @$this->mysqli->next_result();
         }
         $this->reset_caches($tablenames);
         throw $e;
     }
     $this->reset_caches($tablenames);
     return true;
 }
Ejemplo n.º 2
0
 public function executeMulti($sql)
 {
     if (!$this->connection) {
         $this->open();
     }
     $ret = $this->connection->multi_query($sql);
     if (!$ret) {
         $errMsg = "Can't Execute Query:" . $sql;
         $errMsg .= "\n MySQL Message:" . $this->connection->error;
         throw new \RuntimeException($errMsg);
     }
     do {
         if ($this->connection->errno) {
             $errMsg = "Can't Execute Query:" . $sql;
             $errMsg .= "\n MySQL Message:" . $this->connection->error;
             throw new \RuntimeException($errMsg);
         }
         if ($result = $this->connection->store_result()) {
             $result->free_result();
         }
         if (!$this->connection->more_results()) {
             break;
         }
     } while ($this->connection->next_result());
     return $ret;
 }
Ejemplo n.º 3
0
 /**
  * Preform multiple queries on the Database
  * @param string $sql 
  * @return boolean|mysqli_result
  */
 public function MultiQuery($sql)
 {
     $rs = static::$link->multi_query($sql);
     if ($rs) {
         static::__setLastResult($rs);
     }
     static::__setResults($rs);
     return $rs;
 }
Ejemplo n.º 4
0
 public static function persistAuditLogs()
 {
     if (!is_array($_SESSION['auditLog']['sql']) || count($_SESSION['auditLog']['sql']) <= 0) {
         return;
     }
     $config = $_SESSION['auditLog']['database'];
     $hostname = $config['params']['host'];
     $username = $config['params']['username'];
     $password = $config['params']['password'];
     $dbname = $config['params']['dbname'];
     // in the meantime, just use mysqli because of its multi-query support
     $mysqli = new mysqli($hostname, $username, $password, $dbname);
     /* check connection */
     $retry = 10;
     // 10 seconds to retry
     $ctr = 0;
     do {
         $err = mysqli_connect_errno();
     } while ($err && $ctr++ < $retry);
     if ($err) {
         printf("Connect failed: %s\n", mysqli_connect_error());
         return;
     }
     // generate queries
     $queries = implode(";\n", $_SESSION['auditLog']['sql']);
     /* execute multi query */
     $mysqli->multi_query($queries);
     /* close connection */
     $mysqli->close();
 }
Ejemplo n.º 5
0
 public function create_tables($data)
 {
     // Connect to the database
     $mysqli = new mysqli($data['db_hostname'], $data['db_username'], $data['db_password'], $data['db_database']);
     // Check for errors
     if (mysqli_connect_errno()) {
         return false;
     }
     // Open the default SQL file
     $query = file_get_contents('assets/install.sql');
     $pw = $this->password($data['admin_password']);
     $handled_enc = $this->handle_enc_pms($data);
     $new = str_replace("%ENCRYPT_PRIVATE_MESSAGES%", $data['encrypt_private_messages'], $query);
     $new = str_replace("%ALLOW_GUESTS%", $data['allow_guests'], $new);
     $new = str_replace("%FORCE_VENDOR_PGP%", $data['force_vendor_pgp'], $new);
     $new = str_replace("%ELECTRUM_MPK%", $data['electrum_mpk'], $new);
     $new = str_replace("%PASSWORD%", $pw['hash'], $new);
     $new = str_replace("%PUBLIC_KEY%", $handled_enc['public_key'], $new);
     $new = str_replace("%PRIVATE_KEY%", $handled_enc['private_key'], $new);
     $new = str_replace("%PRIVATE_KEY_SALT%", $handled_enc['private_key_salt'], $new);
     $new = str_replace("%REGISTER_TIME%", time(), $new);
     $new = str_replace("%USER_HASH%", substr(hash('sha512', mcrypt_create_iv(32, MCRYPT_DEV_URANDOM)), 0, 16), $new);
     $new = str_replace("%SALT%", $pw['salt'], $new);
     // Execute a multi query
     $mysqli->multi_query($new);
     if (mysqli_connect_errno()) {
         var_dump($mysqli);
         return false;
     }
     // Close the connection
     $mysqli->close();
     return true;
 }
Ejemplo n.º 6
0
 function InitializeData()
 {
     $this->TruncateTables();
     $r = $this->Connection->multi_query($this->GetDataSQL());
     while ($this->Connection->more_results()) {
         $this->Connection->next_result();
     }
 }
Ejemplo n.º 7
0
 /**
  * Performs multiple SQL queries. Results are flushed and not returned. Useful for multiple updates and inserts.
  *
  * @param string $multiSql semicolon separated queries to be sent to the DB
  *
  * @return void
  * @throws \iveeCore\Exceptions\SQLErrorException when the query execution errors out
  */
 public function multiQuery($multiSql)
 {
     $startTime = microtime(true);
     if (!$this->db->multi_query($multiSql)) {
         $exceptionClass = Config::getIveeClassName('SQLErrorException');
         throw new $exceptionClass($this->db->error . "\nQuery: " . $multiSql, $this->db->errno);
     }
     //gather stats about queries
     $this->addQueryTime(microtime(true) - $startTime);
     $this->flushDbResults();
 }
Ejemplo n.º 8
0
function makeInstallation($s)
{
    if ($s['createDb']) {
        /* create BDD */
        $mysqli = new mysqli($s['db_adress'], $s['db_user'], $s['db_password']);
        /* check connection */
        if ($mysqli->connect_errno) {
            printf("Connect failed: %s\n", $mysqli->connect_error);
            exit(24);
        }
        $q = "CREATE DATABASE IF NOT EXISTS `" . $s['db_schema'] . "` /*!40100 DEFAULT CHARACTER SET utf8 */;";
        //echo "Création BDD ::".$q;
        //exit;
        if (!$mysqli->query($q)) {
            echo "Création BDD impossible";
            exit;
        }
        $mysqli->close();
    }
    $mysqli = new mysqli($s['db_adress'], $s['db_user'], $s['db_password'], $s['db_schema']);
    /* execute multi query */
    $mysqli->multi_query(file_get_contents('install/install.sql'));
    while ($mysqli->next_result()) {
    }
    // flush multi_queries
    /* init de la table des dates de reference */
    $start_day = mktime(0, 0, 0, 9, 1, 2014);
    //1er septembre 2014
    $stop_day = mktime(0, 0, 0, 9, 1, 2037);
    //justqu'au 1er septembre 2037, on verra en 2037 si j'utilise encore l'app.
    $nb_day = ($stop_day - $start_day) / 86400;
    $query = "INSERT INTO oko_dateref (jour) VALUES ";
    for ($i = 0; $i <= $nb_day; $i++) {
        $day = date('Y-m-d', mktime(0, 0, 0, date("m", $start_day), date("d", $start_day) + $i, date("Y", $start_day)));
        $query .= "('" . $day . "'),";
    }
    $query = substr($query, 0, strlen($query) - 1) . ";";
    //print_r($query);exit;
    $mysqli->query($query);
    $mysqli->close();
    /* Make Config.php */
    $configFile = file_get_contents('config_sample.php');
    $configFile = str_replace("###_BDD_IP_###", $s['db_adress'], $configFile);
    $configFile = str_replace("###_BDD_USER_###", $s['db_user'], $configFile);
    $configFile = str_replace("###_BDD_PASS_###", $s['db_password'], $configFile);
    $configFile = str_replace("###_BDD_SCHEMA_###", $s['db_schema'], $configFile);
    $configFile = str_replace("###_CONTEXT_###", getcwd(), $configFile);
    $configFile = str_replace("###_TOKEN_###", sha1(rand()), $configFile);
    //$configFile = str_replace("###_TOKEN-API_###",sha1(rand()),$configFile);
    file_put_contents('config.php', $configFile);
    /* Make config.json */
    $param = array("chaudiere" => $s['oko_ip'], "tc_ref" => $s['param_tcref'], "poids_pellet" => $s['param_poids_pellet'], "surface_maison" => $s['surface_maison'], "get_data_from_chaudiere" => $s['oko_typeconnect'], "send_to_web" => "0");
    file_put_contents('config.json', json_encode($param));
}
Ejemplo n.º 9
0
 /**
  * @param string $query
  * @return bool|null
  */
 public function multi_query($query)
 {
     $result = parent::multi_query($query);
     if ($this->errno) {
         $error = $this->error;
         $this->rollback();
         $this->ThrowQueryError($query, $error);
         return null;
     } else {
         return $result;
     }
 }
Ejemplo n.º 10
0
 /**
  * Executes a multi query string; typically concatenated by semicolon
  * @param sring $query
  * @throws DBExceptions\DatabaseException Raises an exception in case of an error
  */
 public function ExecuteMultiQuery($query)
 {
     $result = $this->db->multi_query($query);
     if ($result) {
         while ($this->db->next_result()) {
         }
         //overgo the results!
     }
     if (!$result) {
         throw new DBExceptions\DatabaseException('Error in multi query', 101, $query);
     }
 }
Ejemplo n.º 11
0
function getSQLResultSet($commando)
{
    $mysqli = new mysqli("localhost", "root", "12345", "conexionandroid");
    $mysqli->query("SET NAMES 'utf8'");
    if ($mysqli->connect_error) {
        printf("Connect failed: %s\n", $mysqli->connect_error);
        exit;
    }
    if ($mysqli->multi_query($commando)) {
        return $mysqli->store_result();
    }
    $mysqli->close();
}
Ejemplo n.º 12
0
 /**
  * @param $query
  * @return bool|mysqli_result
  */
 public function query($query)
 {
     if ($res = $this->link->multi_query($query)) {
         do {
             if ($res = mysqli_store_result($this->link)) {
                 mysqli_free_result($res);
             }
             if (mysqli_more_results($this->link)) {
             }
         } while (mysqli_next_result($this->link));
     }
     return $res;
 }
Ejemplo n.º 13
0
 /**
  * 发送批量查询语句
  * 记作一次查询,只返回最后的查询结果
  */
 public function xquery($sql, $noerror = false)
 {
     $this->result = $this->conn->multi_query($sql);
     $this->queryCount++;
     if (!$this->result) {
         if ($noerror == true) {
             return false;
         } else {
             throw new Exception("MySQL 批量语句执行错误:<br/><b>语句:</b>{$sql}<br/><b>错误:</b>" . $this->geterror(), 10000);
         }
     } else {
         return $this->result;
     }
 }
Ejemplo n.º 14
0
 public function init()
 {
     $this->load->helper(array('form', 'file', 'url'));
     $this->load->library(array('form_validation'));
     $cartPath = dirname(FCPATH);
     $testConfig = is_writeable($cartPath . '/application/config/');
     $testUploads = is_writeable($cartPath . '/uploads/');
     $testIntl = class_exists('Locale');
     $errors = !$testConfig ? '<div class="alert alert-danger" role="alert">The folder "' . $cartPath . '/application/config" must be writable.</div>' : '';
     $errors .= !$testUploads ? '<div class="alert alert-danger" role="alert">The folder "' . $cartPath . '/uploads" must be writable.</div>' : '';
     $errors .= !$testIntl ? '<div class="alert alert-danger" role="alert">The PHP_INTL Library is required for GoCart and is not installed on your server. <a href="http://php.net/manual/en/book.intl.php">Read More</a></div>' : '';
     $this->form_validation->set_rules('hostname', 'Hostname', 'required');
     $this->form_validation->set_rules('database', 'Database Name', 'required');
     $this->form_validation->set_rules('username', 'Username', 'required');
     $this->form_validation->set_rules('password', 'Password', 'trim|required');
     $this->form_validation->set_rules('prefix', 'Database Prefix', 'trim');
     if ($this->form_validation->run() == FALSE || $errors != '') {
         $this->form_validation->set_error_delimiters('<div class="alert alert-danger">', '</div>');
         $errors .= validation_errors();
         $this->load->view('index', ['errors' => $errors]);
     } else {
         $dbCred = $this->input->post();
         //test the database
         mysqli_report(MYSQLI_REPORT_STRICT);
         try {
             $db = new mysqli($dbCred['hostname'], $dbCred['username'], $dbCred['password'], $dbCred['database']);
         } catch (Exception $e) {
             $errors = '<div class="alert alert-danger" role="alert">There was an error connecting to the database</div>';
             $this->load->view('index', ['errors' => $errors]);
             return;
         }
         //create the database file
         $database = $this->load->view('database', $this->input->post(), true);
         $myfile = fopen($cartPath . '/application/config/database.php', "w");
         fwrite($myfile, $database);
         fclose($myfile);
         $sql = str_replace('gc_', $dbCred['prefix'], file_get_contents(FCPATH . 'database.sql'));
         $db->multi_query($sql);
         // run the dump
         while ($db->more_results() && $db->next_result()) {
         }
         //run through it
         //set some basic information in settings
         $query = "INSERT INTO `{$dbCred['prefix']}settings` (`code`, `setting_key`, `setting`) VALUES\n\t\t\t('gocart', 'theme', 'default'),\n\t\t\t('gocart', 'locale', 'en_US'),\n\t\t\t('gocart', 'currency_iso', 'USD'),\n\t\t\t('gocart', 'new_customer_status', '1'),\n\t\t\t('gocart', 'order_statuses', '{\"Order Placed\":\"Order Placed\",\"Pending\":\"Pending\",\"Processing\":\"Processing\",\"Shipped\":\"Shipped\",\"On Hold\":\"On Hold\",\"Cancelled\":\"Cancelled\",\"Delivered\":\"Delivered\"}'),\n\t\t\t('gocart', 'products_per_page', '24'),\n\t\t\t('gocart', 'default_meta_description', 'Thanks for installing GoCart.'),\n\t\t\t('gocart', 'default_meta_keywords', 'open source, ecommerce'),\n\t\t\t('gocart', 'timezone', 'UTC');";
         $db->query($query);
         $db->close();
         $url = dirname((isset($_SERVER['HTTPS']) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']) . '/admin';
         header('Location: ' . dirname($url) . '/admin');
     }
 }
Ejemplo n.º 15
0
 function addUserData($userName, $firstName, $lastName, $staffId, $designation, $email_Id, $phoneNumber)
 {
     $sql = "INSERT INTO `nicdata`(`userName`, `firstName`, `lastName`, `staffId`, `designation`, `email_Id`,`phoneNumber`) ";
     $sql .= "VALUES ('" . $userName . "','" . $firstName . "','" . $lastName . "','" . $staffId . "','" . $designation . "','" . $email_Id . "','" . $phoneNumber . "')";
     echo $sql;
     $conn = new mysqli(constant("SERVER_NAME_NIC"), constant("DB_USER_NIC"), constant("DB_PASSWORD_NIC"), constant("DB_NAME_NIC"));
     if ($conn->connect_error) {
         die("Connection failed: " . $conn->connect_error);
     }
     if ($conn->multi_query($sql) === true) {
         $result = "Success";
     }
     $conn->close();
 }
Ejemplo n.º 16
0
 function dummy_data($data)
 {
     // Connect to the database
     $mysqli = new mysqli($data['hostname'], $data['username'], $data['password'], $data['database']);
     // Check for errors
     if (mysqli_connect_errno()) {
         return false;
     }
     // Open the default SQL file
     $query = file_get_contents('sql_files/3-dummy_data-optional.sql');
     // Execute a multi query
     $mysqli->multi_query($query);
     // Close the connection
     $mysqli->close();
 }
Ejemplo n.º 17
0
function multi_query($query)
{
    global $dburl;
    global $dbusername;
    global $dbpassword;
    global $dbname;
    $conn = new mysqli($dburl, $dbusername, $dbpassword, $dbname);
    // Check connection
    if ($conn->connect_error) {
        $error_connecting = true;
    } else {
        @($result = $conn->multi_query($query));
    }
    $conn->close();
    return $result;
}
Ejemplo n.º 18
0
 function update_db($data)
 {
     // Connect to the database
     $mysqli = new mysqli($data['hostname'], $data['username'], $data['password'], $data['database']);
     // Check for errors
     if (mysqli_connect_errno()) {
         return false;
     }
     // Open the default SQL file
     $query = $data['dbtables'];
     // Execute a multi query
     $mysqli->multi_query($query);
     // Close the connection
     $mysqli->close();
     return true;
 }
Ejemplo n.º 19
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 public function testSetUp()
 {
     $testSql = dirname(dirname(dirname(dirname(__FILE__)))) . '/testfiles/test.sql';
     $testConfig = dirname(dirname(dirname(dirname(__FILE__)))) . '/testfiles/test_config.json';
     //create test database
     $mysqli = new mysqli("localhost", "root", "root");
     $mysqli->query("CREATE DATABASE airymvc_unit_test");
     $mysqli->select_db("airymvc_unit_test");
     $query = file_get_contents($testSql);
     $mysqli->multi_query($query);
     $mysqli->close();
     $configArr = json_decode(file_get_contents($testConfig), TRUE);
     $dbConfigArr = $configArr["%application_configs"][0]["%db"][0];
     $this->object = new SqlDb();
     $this->object->initDb($dbConfigArr);
 }
Ejemplo n.º 20
0
 function create_tables($data)
 {
     // Connect to the database
     $mysqli = new mysqli($data['hostname'], $data['username'], $data['password'], $data['database']);
     // Check for errors
     if (mysqli_connect_errno()) {
         return false;
     }
     // Open the default SQL file
     $query = file_get_contents('assets/install.sql');
     // Execute a multi query
     $mysqli->multi_query($query);
     // Close the connection
     $mysqli->close();
     return true;
 }
Ejemplo n.º 21
0
 /**
  * Create new databases.
  */
 protected static function createDB()
 {
     // Setup DB
     $m = new \mysqli(ini_get('mysqli.default_host'), ini_get('mysqli.default_user') ?: 'root', ini_get('mysqli.default_pw'));
     if ($m->connect_error) {
         throw new \PHPUnit_Framework_SkippedTestError("Failed to connect to mysql: " . $m->connect_error);
     }
     $sql = file_get_contents(__DIR__ . '/../../support/db.sql');
     if (!$m->multi_query($sql)) {
         throw new \PHPUnit_Framework_SkippedTestError("Failed to initialise DBs: " . $m->error);
     }
     // Make sure everything is executed
     do {
         $m->use_result();
     } while ($m->more_results() && $m->next_result());
     self::$reuse_db = true;
 }
Ejemplo n.º 22
0
 function create_tables($data, $user = NULL, $code = NULL)
 {
     // Connect to the database
     $mysqli = new mysqli($data['hostname'], $data['username'], $data['password'], $data['database']);
     // Check for errors
     if (mysqli_connect_errno()) {
         return false;
     }
     // Open the default SQL file
     $query = $data['dbtables'];
     //update username and code
     $query .= " UPDATE `sma_settings` SET `envato_username`= '" . $user . "',`purchase_code`= '" . $code . "' WHERE setting_id = 1;";
     // Execute a multi query
     $mysqli->multi_query($query);
     // Close the connection
     $mysqli->close();
     return true;
 }
Ejemplo n.º 23
0
function init_db()
{
    global $db_host, $db_user, $db_pass, $db_name, $db_port;
    $db = new mysqli($db_host, $db_user, $db_pass, 'information_schema', $db_port);
    if ($db->connect_error) {
        die("open information_schema failed, [" . $db->connect_errno . "]: " . $db->connect_error);
    }
    $sql = "SELECT `SCHEMA_NAME` FROM `SCHEMATA` WHERE `SCHEMA_NAME` = '" . $db_name . "'";
    $result = $db->query($sql);
    $need_init_db = $result->fetch_array(MYSQLI_ASSOC) == false;
    $result->close();
    $sql = "SELECT `TABLE_NAME` FROM `TABLES` WHERE `TABLE_NAME` = 'db_version' AND `TABLE_SCHEMA` = '" . $db_name . "'";
    $result = $db->query($sql);
    $need_init_tb = $result->fetch_array(MYSQLI_ASSOC) == false;
    $result->close();
    if ($need_init_db) {
        $sql = "CREATE DATABASE `" . $db_name . "` CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';\n";
        if ($db->query($sql) === FALSE) {
            die("create database failed, [" . $db->errno . "]: " . $db->error);
        }
    }
    $sql = "USE `" . $db_name . "`";
    $db->query($sql);
    if ($need_init_tb) {
        $sql = "CREATE TABLE `db_version` (`version` INT, `change_time` INT NOT NULL DEFAULT 0);\nINSERT INTO `db_version` VALUES (0, 0);\n";
        if ($db->multi_query($sql) === FALSE) {
            die("create database failed, [" . $db->errno . "]: " . $db->error);
        }
    }
    $db->close();
    $db = new mysqli($db_host, $db_user, $db_pass, $db_name, $db_port);
    $sql = "SELECT `version` FROM `db_version`";
    $result = $db->query($sql);
    $row = $result->fetch_array(MYSQLI_ASSOC);
    $result->close();
    if ($row == FALSE) {
        $db->query("INSERT INTO `db_version` VALUES (0, 0);");
        $version = 0;
    } else {
        $version = $row['version'];
    }
    $db->close();
    return $version;
}
Ejemplo n.º 24
0
function create_database($hostname, $username, $password, $database)
{
    $h = $hostname;
    $u = $username;
    $p = $password;
    $d = $database;
    $conn = new mysqli($h, $u, $p, $d);
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }
    $sql = "CREATE TABLE users (\n\t\t\tid INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,\n\t\t\tfirstname VARCHAR(255) NOT NULL,\n\t\t\tlastname VARCHAR(255) NOT NULL,\n\t\t\temail VARCHAR(255) NOT NULL,\n\t\t\tpassword VARCHAR(255) NOT NULL,\n\t\t\thash VARCHAR(255) NOT NULL,\n\t\t\tforgot_password_hash VARCHAR(255) NOT NULL,\n\t\t\tstatus ENUM('1', '0') NOT NULL\n\t\t\t);";
    if ($conn->multi_query($sql) === TRUE) {
        echo "Database Created Successfully! Please Delete The \"install\" Directory For Safety.";
    } else {
        echo "Error creating table: " . $conn->error;
    }
    $conn->close();
}
Ejemplo n.º 25
0
function execute_query($mysqli, $query)
{
    $bcloseconnection = false;
    // did we get passed a valid connection (i.e. did the calling function already make the connection to the db for us?)
    if (!isset($mysqli)) {
        //echo '<br>execute_query: opening db connection';
        $bcloseconnection = true;
        // Connect to the database
        $mysqli = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);
        // check connection
        if (mysqli_connect_errno()) {
            log_error(sprintf("sql_execute: Connect failed: %s\n", mysqli_connect_error()));
            return false;
        }
    }
    //echo '<br>query='.$query;
    // execute the query
    if ($mysqli->multi_query($query)) {
        // Setup an incrementing count of the result set;
        $result_set_id = 0;
        do {
            if ($result = $mysqli->store_result()) {
                $ary_results[$result_set_id] = $result;
                // Increment the result set
                $result_set_id++;
            }
        } while ($mysqli->more_results() && $mysqli->next_result());
        // need to check if we got any resultsets back into the array...if not, the query was probably still valid so return TRUE
        if (!is_array($ary_results)) {
            return true;
        }
    } else {
        echo $mysqli->error;
        //log_error(sprintf("sql_execute: the query '%s' failed to execute due to the following error: '%s'", $query, $mysqli->error));
        return false;
    }
    // if we had to open the connection, then close it
    if ($bcloseconnection) {
        //echo '<br>execute_query: closing db connection';
        $mysqli->close();
    }
    return $ary_results;
}
Ejemplo n.º 26
0
 function create_tables($data)
 {
     // Connect to the database
     $mysqli = new mysqli($data['hostname'], $data['db_user'], $data['db_password'], $data['db_name']);
     // Check for errors
     if ($mysqli->connect_errno) {
         $message = "Failed to connect to MySQL: " . $mysqli->connect_error;
         return false;
     }
     // Open the default SQL file
     $query = file_get_contents('assets/install.sql');
     // Execute a multi query
     if ($mysqli->multi_query($query)) {
         while ($mysqli->next_result()) {
         }
     }
     // Close the connection
     $mysqli->close();
     return true;
 }
Ejemplo n.º 27
0
 /**
  * imports a sql file via mysqli
  *
  * @param  string $sql
  *
  * @return int  Number of Sql queries made, -1 if error
  */
 public function import_sql($sql)
 {
     //connect via mysqli for easier db import
     $mysqli = new \mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
     // Run the SQL
     $i = 1;
     if ($mysqli->multi_query($sql)) {
         do {
             if ($mysqli->more_results()) {
                 $mysqli->next_result();
                 $i++;
             }
         } while ($mysqli->more_results());
     }
     if ($mysqli->errno) {
         return -1;
     }
     mysqli_close($mysqli);
     return $i;
 }
Ejemplo n.º 28
0
 /**
  * imports a sql file via mysqli
  *
  * @param  string   $sql
  * @param \WP_Error $error
  *
  * @return int  Number of Sql queries made, -1 if error
  */
 public function import_sql($sql, $error)
 {
     //connect via mysqli for easier db import
     $mysqli = new \mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
     // Run the SQL
     $i = 1;
     if ($mysqli->multi_query($sql)) {
         do {
             if ($mysqli->more_results()) {
                 $mysqli->next_result();
                 $i++;
             }
         } while ($mysqli->more_results());
     }
     if ($mysqli->errno) {
         $error->add('sql_import_error', __('<b>Mysqli Error:</b> ' . $mysqli->error, 'search-and-replace'));
         return -1;
     }
     mysqli_close($mysqli);
     return $i;
 }
Ejemplo n.º 29
0
function makeInstallation($s)
{
    if ($s['createDb']) {
        /* create BDD */
        $mysqli = new mysqli($s['db_adress'], $s['db_user'], $s['db_password']);
        /* check connection */
        if ($mysqli->connect_errno) {
            printf("Connect failed: %s\n", $mysqli->connect_error);
            exit;
        }
        $q = "CREATE DATABASE IF NOT EXISTS `" . $s['db_schema'] . "` /*!40100 DEFAULT CHARACTER SET utf8 */;";
        //echo "Création BDD ::".$q;
        //exit;
        if (!$mysqli->query($q)) {
            echo "Création BDD impossible";
            exit;
        }
        $mysqli->close();
    }
    $mysqli = new mysqli($s['db_adress'], $s['db_user'], $s['db_password'], $s['db_schema']);
    /* execute multi query */
    $mysqli->multi_query(file_get_contents('install/install.sql'));
    while ($mysqli->next_result()) {
    }
    // flush multi_queries
    $mysqli->close();
    /* Make Config.php */
    $configFile = file_get_contents('config_sample.php');
    $configFile = str_replace("###_BDD_IP_###", $s['db_adress'], $configFile);
    $configFile = str_replace("###_BDD_USER_###", $s['db_user'], $configFile);
    $configFile = str_replace("###_BDD_PASS_###", $s['db_password'], $configFile);
    $configFile = str_replace("###_BDD_SCHEMA_###", $s['db_schema'], $configFile);
    $configFile = str_replace("###_CONTEXT_###", getcwd(), $configFile);
    $configFile = str_replace("###_TOKEN_###", sha1(rand()), $configFile);
    //$configFile = str_replace("###_TOKEN-API_###",sha1(rand()),$configFile);
    file_put_contents('config.php', $configFile);
    /* Make config.json */
    $param = array("chaudiere" => $s['oko_ip'], "tc_ref" => $s['param_tcref'], "poids_pellet" => $s['param_poids_pellet'], "surface_maison" => $s['surface_maison'], "get_data_from_chaudiere" => $s['oko_typeconnect'], "send_to_web" => "0");
    file_put_contents('config.json', json_encode($param));
}
Ejemplo n.º 30
0
 /**
  * Executes multiple queries given in one string within a single request.
  *
  * @param  string $sql The string with the multiple queries.
  * @return boolean false if the first statement failed. Otherwise true.
  */
 public function queryMulti($sql)
 {
     $result = false;
     $sql = $this->getSqlWithPrefix($sql);
     /*
      * Executing the multiple queries.
      */
     if ($this->conn->multi_query($sql)) {
         while ($this->conn->more_results()) {
             /*
              * If more results are available from the multi_query call we go
              * to the next result and free its memory usage.
              */
             $this->conn->next_result();
             $result = $this->conn->store_result();
             if ($result) {
                 $result->free();
             }
         }
     }
     return $result;
 }