Example #1
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;
 }
 /**
  * Force buffering
  *
  * @throws Exception\RuntimeException
  */
 public function buffer()
 {
     if ($this->resource instanceof \mysqli_stmt && $this->isBuffered !== true) {
         if ($this->position > 0) {
             throw new Exception\RuntimeException('Cannot buffer a result set that has started iteration.');
         }
         $this->resource->store_result();
         $this->isBuffered = true;
     }
 }
 /**
  * @desc Get only multi query result
  *
  * @access public
  * @return mixed
  */
 public function multi_query_result()
 {
     $data = array();
     do {
         if ($this->result = $this->link->store_result()) {
             $data[] = $this->result->fetch_all($this->fetchMode);
             $this->result->free();
         }
     } while ($this->link->more_results() && $this->link->next_result());
     return $data;
 }
Example #4
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();
}
Example #5
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;
}
Example #6
0
 /**
  * Get all array data
  *
  * @return array
  */
 public function getFetchArrays()
 {
     $data = array();
     if ($this->resource instanceof \mysqli_result) {
         $result = $this->resource;
     } else {
         if ($this->resource instanceof \mysqli_stmt) {
             $result = $this->resource->get_result();
         } else {
             if ($this->resource instanceof \mysqli) {
                 $result = $this->resource->store_result();
             }
         }
     }
     while ($row = $result->fetch_array(\MYSQLI_ASSOC)) {
         $data[] = $row;
     }
     return $data;
 }
Example #7
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;
 }
 $res->priv_level = $_SESSION['priv_level'];
 $query = "SELECT user_name FROM summaries WHERE net_id='{$net_id}'; ";
 $result = $mysqli->query($query);
 list($user) = $result->fetch_row();
 if (empty($user)) {
     $course_id = $_SESSION['canvas_course_id'];
     $query = "INSERT INTO summaries (net_id, user_name, course_id) VALUES\n        ('{$net_id}','{$res->full_name}', '{$course_id}'); ";
     $mysqli->query($query);
 }
 $query = "SELECT * FROM profiles WHERE net_id='{$net_id}' ORDER BY full_name; ";
 $query .= "SELECT * FROM connections WHERE net_id='{$net_id}' ORDER BY profile_id1, profile_id2; ";
 $query .= "SELECT p.net_id, s.user_name, COUNT(*) AS network_size, SUM(same_school) AS agg_school,\n            SUM(is_faculty) AS agg_faculty, SUM(same_industry) as agg_industry, SUM(more_senior) as agg_senior,\n            SUM(same_level) as agg_level, SUM(more_junior) as agg_junior, SUM(same_gender) AS agg_gender,\n            SUM(same_nationality) AS agg_nationality,\n            SUM(same_ethnicity) AS agg_ethnicity, SUM(tech_skill) AS agg_tech,\n            SUM(finance_skill) AS agg_finance, SUM(ops_skill) AS agg_ops,\n            SUM(sales_skill) AS agg_sales, SUM(prod_skill) AS agg_prod,\n            SUM(gm_skill) AS agg_gm, SUM(vc_skill) AS agg_vc, SUM(other_skill) AS agg_other,\n            SUM(same_skill) AS agg_skill,\n            (SELECT COUNT(*) FROM connections c WHERE c.net_id=p.net_id) AS num_connections\n        FROM profiles p\n        INNER JOIN summaries s\n            ON s.net_id=p.net_id\n        GROUP BY net_id; ";
 $mysqli->multi_query($query);
 if ($mysqli->more_results()) {
     $mysqli->next_result();
     $result = $mysqli->store_result();
     $json = array();
     while ($row = $result->fetch_assoc()) {
         $json[] = $row;
     }
     $res->profiles = $json;
 }
 if ($mysqli->more_results()) {
     $mysqli->next_result();
     $result = $mysqli->store_result();
     $json = array();
     while ($row = $result->fetch_assoc()) {
         $json[] = $row;
     }
     $res->connections = $json;
 }
    function StoredProcedureArray2($query="") {
        //Me conecto a la base de datos

        $mysqli = new mysqli("atc-nh-natsdb.nationalnet.com", "staffcenter", "XgwofvLY2ayLf", "staffcenter");

        /* check connection */
        if (mysqli_connect_errno()) {
            printf("<br />Failed to connect to the database: %s\n", mysqli_connect_error());
            exit();
        }

        //LLama al stored procedure
        if ($mysqli->multi_query($query)) {
            /* guarda el resultado del stored procedure */
            $result = $mysqli->store_result();
            $mysqli->kill($mysqli->thread_id);
            $mysqli->close();
            return $result;
        }
    }
CREATE TEMPORARY TABLE IF NOT EXISTS _cibh_maxnodecount ENGINE=MEMORY AS (
        SELECT
                BlockHeight,
                MAX(CountNode) MaxCountNode
        FROM
                _cibh_nodecount
        GROUP BY
                BlockHeight
        );
SELECT NC.BlockHeight BlockHeight, BlockMNPayee, BlockMNRatio FROM _cibh_maxnodecount MNC, _cibh_nodecount NC WHERE MNC.BlockHeight = NC.BlockHeight AND MNC.MaxCountNode = NC.CountNode;
EOT;
$sql = sprintf($sql, $blockfrom, $blockto, $testnet);
xecho("Executing query....\n");
//echo $sql."\n";
$blockhist = array();
if ($mysqli->multi_query($sql) && $mysqli->more_results() && $mysqli->next_result() && $mysqli->more_results() && $mysqli->next_result() && $mysqli->more_results() && $mysqli->next_result() && $mysqli->more_results() && $mysqli->next_result() && ($result = $mysqli->store_result())) {
    $update = array();
    while ($row = $result->fetch_assoc()) {
        $update[] = sprintf("(%d,%d,'%s',%.9f)", $testnet, intval($row['BlockHeight']), $row['BlockMNPayee'], floatval($row['BlockMNRatio']));
    }
    xecho("  Done (" . count($update) . " computed)\n");
    $sql = "INSERT INTO cmd_info_blocks (BlockTestnet, BlockId, BlockMNPayeeExpected, BlockMNValueRatioExpected) VALUES " . implode(",", $update) . " ON DUPLICATE KEY UPDATE BlockMNPayeeExpected = VALUES(BlockMNPayeeExpected), BlockMNValueRatioExpected = VALUES(BlockMNValueRatioExpected)";
    //  echo $sql."\n";
    xecho("Updating expected values in block database:\n");
    if ($result = $mysqli->query($sql)) {
        xecho("  Done (" . $mysqli->info . ")\n");
    } else {
        xecho("  Error (" . $mysqli->errno . ': ' . $mysqli->error . ")\n");
    }
} else {
    xecho(" Failed (" . $mysqli->errno . ": " . $mysqli->error . ")\n");
    $response["message"] = "Song id not set.";
    die(json_encode($response));
}
$sql = new mysqli("localhost");
if (!$sql->select_db("droidbox")) {
    die("Unable to connect to database.");
}
$cmd = "CALL get_next_song_queue(" . $_POST["songID"] . ");";
$cmd .= "SELECT id,title,artist,file_path,length FROM song,queue \n\t\tWHERE id = songID and priority >= 0 ORDER BY request_type, priority DESC, time_requested LIMIT 1;";
if ($sql->multi_query($cmd)) {
    if (!$sql->next_result()) {
        $response["success"] = 1;
        $response["message"] = "No next result.";
        die(json_encode($response));
    }
    if (!($result = $sql->store_result())) {
        $response["success"] = 1;
        $response["message"] = "No result to store.";
        die(json_encode($response));
    }
    if (!($row = $result->fetch_row())) {
        $response["success"] = 1;
        $response["message"] = "Queue is empty.";
        die(json_encode($response));
    } else {
        $response["songID"] = $row[0];
        $response["title"] = $row[1];
        $response["artist"] = $row[2];
        $response["filepath"] = $row[3];
        $reponse["length"] = $row[4];
        $result->free();
Example #12
0
 /**
  * 撤销订单
  * @param $type 彩种
  * @param $pid 方案编号
  */
 public function rev($type = 'dlt', $pid = null)
 {
     if (intval($pid) * 1 < 1) {
         remind::set("方案编号 为空不可操作!", '/lottnum/order/index/' . $type . '/?' . http_build_query($_GET), 'error');
     }
     $this->loaddb();
     $gcancelflag = true;
     $prow = self::$pdb->query("select uid,nums,rgnum,baodi,baodimoney,restat,onemoney from plans_lotty_orders where id='" . $pid . "'")->result_array(FALSE);
     if ($prow[0]['restat'] == 1) {
         remind::set("已做过撤单处理,不可重复撤单!", '/lottnum/order/index/' . $type . '/?' . http_build_query($_GET), 'error');
     }
     $grows = self::$pdb->query("select id,restat from sale_prousers where pid='" . $pid . "'")->result_array(FALSE);
     /*
      * 循环调用存储过程出现Commands out of sync; you can't run this command now 
      * 暂时用mysqli的原生方法来做
      */
     $config = Kohana::config('database.default');
     extract($config['connection']);
     $mysqli = new mysqli($host, $user, $pass, $database, $port);
     if (mysqli_connect_errno()) {
         remind::set("数据库异常!", '/lottnum/order/index/' . $type . '/?' . http_build_query($_GET), 'error');
     }
     if (is_array($grows)) {
         foreach ($grows as $row) {
             if ($row['restat'] == 0) {
                 if ($mysqli->multi_query("call rev_order(" . $row['id'] . ", -- 根单编号 \n\t\t\t                                    1, -- 撤单类型 1 方案撤单 2 跟单人撤销\n\t\t\t\t\t\t\t                    2011, -- 交易流水号\n\t\t\t                                   @stat)")) {
                     do {
                         if ($result = $mysqli->store_result()) {
                             while ($row = $result->fetch_row()) {
                                 if ($row[0] != 'succ') {
                                     $gcancelflag = false;
                                 }
                             }
                             $result->close();
                         }
                     } while ($mysqli->next_result());
                 } else {
                     $gcancelflag = false;
                 }
             }
         }
     }
     //操作方案表及清保
     if ($prow[0]['baodi'] == 1) {
         if ($mysqli->multi_query("call clearbaodi(" . $pid . ", -- 方案编号\n                         0, -- 清保类型 0 只清保 1 清保加认购\n                         @stat)")) {
             do {
                 if ($result = $mysqli->store_result()) {
                     while ($row = $result->fetch_row()) {
                         if ($row[0] == -1) {
                             $gcancelflag = false;
                         }
                     }
                     $result->close();
                 }
             } while ($mysqli->next_result());
         } else {
             $gcancelflag = false;
         }
     }
     if ($gcancelflag) {
         $crow = self::$pdb->query("update plans_lotty_orders set restat=1 where id='" . $pid . "'");
         remind::set("撤单成功!", '/lottnum/order/index/' . $type . '/?' . http_build_query($_GET), 'success');
     } else {
         //$result = array('stat'=>108,'info'=>'撤单失败!');
         remind::set("撤单失败!", '/lottnum/order/index/' . $type . '/?' . http_build_query($_GET), 'error');
     }
 }
/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
header('Content-Type:application/json');
$OK = true;
$db = new mysqli("localhost", "root", "", "Bank");
if ($db->connect_error) {
    $ok = false;
}
$fil = file_get_contents('../DAL/Bank.sql');
$res = $db->multi_query($fil);
if ($res) {
    do {
        if ($result = $db->store_result()) {
            if ($result == false) {
                $OK = false;
            }
            $result->free();
        }
        $db->more_results();
    } while ($db->next_result());
} else {
    $OK = false;
}
$db->close();
if ($OK) {
    echo json_encode("OK");
} else {
    echo json_encode("Feil");
 /**
  * Executes HANDLER query.
  *
  * @param int $returnType Indicates what type of data should be produced from the result set. <br>
  * The possible values are the constants:<br>
  * <var>ASSOCIATIVE</var>, <var>NUMERIC</var>, <var>ASSOC_NUM</var>, <var>OBJECT</var> or <var>STRING</var>.
  *
  * @param string $table Table Name to perform SQL query on.
  *
  * @param string|array $targetColumn Target column in <var>$table</var> to get data from.<br>
  * The possible types are:<br>
  * <b>string</b>: Executes a query on a single column.<br>
  * <b>array</b>: Executes a query on multiple columns within the passed array.
  *
  * @param string $scope [optional] <br> Scope of the query. <br>
  * The possible values are the constants: <br>
  * <var>ALL</var> Retrieve all records found limited by <var>$limit</var>.<br>
  * <var>FIRST</var> Retrieve first record(s) in <var>$table</var> limited by <var>$limit</var>.<br>
  * <var>LAST</var> Retrieve the last record(s) in <var>$table</var> based on <var>$index</var>, and limited by <var>$limit</var>.
  *
  * @param int $limit [optional] <br> Limits the result set to <var>$limit</var> <br> with default value 1.
  *
  * @param string $index [optional] <br> Required only if <var>$scope</var> = <var>LAST</var>.
  *
  * @param string|array $whereColumn [optional] <br>Adds a <b>WHERE</b> statement to the query, in association with <var>$whereValue</var>.<br>
  * The possible types are:<br>
  * <b>string</b>: Single column name.<br>
  * <b>array</b>: Multiple column names within the passed array.
  *
  * @param string|array $whereValue [optional]<br> Requires <var>$whereColumn</var> existence.
  * The possible types are:<br>
  * <b>string</b>: Single column value.<br>
  * <b>array</b>: Multiple column values within the passed array.
  *
  * @param string|array $relationalOperator [optional]<br>
  * Required if <b>WHERE</b> statement exists.<br>
  * The possible values are the constants:<br>
  * <var>R_EQUAL</var>, <var>R_LESS</var>, <var>R_GREATER</var>, <var>R_LESS_EQUAL</var> or <var>R_GREATER_EQUAL</var>.<br>
  * <b>string</b>: Specifies the use of a unified operator between each <var>$whereColumn</var> and <var>$whereValue</var>.<br>
  * <b>array</b>: Multiple operators to use in the order passed.
  *
  * @param string|array $logicalOperator [optional]<br>
  * Required if multiple column <b>WHERE</b> statement exists.<br>
  * The possible values for this parameter are the constants:<br>
  * <var>BW_OR</var>, <var>BW_AND</var> or <var>BW_XOR</var><br>
  * <b>string</b>: Specifies the use of a unified operator between each pair of <var>$whereColumn</var> and <var>$whereValue</var>.<br>
  * <b>array</b>: Multiple operators to use in the passed order.
  *
  * @param string $extras [optional]<br>
  * Add extra MySQL statement(s) to the query.
  *
  * @return array Returns an array if <var>$returnType</var> is <var>ASSOCIATIVE</var>, <var>NUMERIC</var> or <var>ASSOC_NUM</var>.<br><br>
  *
  * @return array Returns a two dimensional array if the result set has more than 1 record.<br><br>
  *
  * @return array Returns an object if <var>$returnType</var> is <var>OBJECT</var>
  * where the attributes of the object represent the names of the fields found within the result set.<br><br>
  *
  * @return string Returns a string if <var>$returnType</var> is <var>STRING</var>.<br><br>
  *
  * @return NULL Returns <b>NULL</b> if the results set is empty.<br><br>
  *
  * @return boolean Returns <b>FALSE</b> and triggers <var>mysqli_error</var> on failure.
  *
  * @link http://dev.mysql.com/doc/refman/5.6/en/handler.html
  */
 public function handler($returnType, $table, $targetColumn, $scope, $limit = 1, $index = NULL, $whereColumn = NULL, $whereValue = NULL, $relationalOperator = "", $logicalOperator = "")
 {
     if (!isset($table) || !isset($targetColumn) || !isset($scope) || !isset($returnType)) {
         throw new ErrorException("(200) Empty argument/s supplied.");
     }
     if ($returnType > self::STRING || $returnType < self::ASSOCIATIVE) {
         throw new ErrorException("(201) Supplied \$returnType {$returnType} Not Found.");
     }
     if ($scope != self::ALL && $scope != self::FIRST && $scope != self::LAST) {
         throw new ErrorException("(202) Supplied \$scope {$scope} Not Found.");
     }
     if (isset($index) && $scope != self::LAST) {
         throw new ErrorException("(203) Cannot perform a HANDLER query with \$scope of MySQLiQuery::FIRST or MySQLiQuery::ALL with defined \$index.");
     }
     if ($scope === self::LAST && !isset($index)) {
         throw new ErrorException("(204) \$index is required for \$scope = MySQLiQuery::LAST.");
     }
     $whereString = $this->setWhereString($whereColumn, $whereValue, $relationalOperator, $logicalOperator, 205);
     $queryString = "HANDLER " . $table . " OPEN;";
     $queryString .= "HANDLER " . $table . " READ " . ($scope === self::LAST ? $index . " " . self::LAST : self::FIRST) . $whereString . " LIMIT " . $limit . ";";
     $queryString .= "HANDLER " . $table . " CLOSE;";
     parent::multi_query($queryString);
     parent::next_result();
     $this->query = parent::store_result();
     if ($this->query) {
         $rowsNumber = $this->query->num_rows;
         if ($rowsNumber == 0) {
             return NULL;
         }
         $queryResult = $targetColumn === "*" ? $this->setReturnObject($returnType) : $this->setCustomReturnObject($returnType, $targetColumn);
         $this->query->free();
         parent::next_result();
         return $this->singularReturn || $returnType === self::STRING ? $rowsNumber > 1 && $returnType != self::STRING ? $queryResult : $queryResult[0] : $queryResult;
     } else {
         trigger_error("210) " . $this->getError(), E_USER_ERROR);
         return FALSE;
     }
 }
Example #15
0
 private function getLastUpdateSQL()
 {
     global $conf;
     $mysqli = new mysqli($conf["db_host"], $conf["db_user"], $conf["db_pass"], $conf["db_name"], $conf["db_port"]);
     $this->pageStart = 0;
     $this->perPage = 1;
     $proc = "CALL PLSearch('{$this->searchTerm}', '{$this->statusString}', '{$this->genderString}', '{$this->ageString}', '{$this->hospitalString}', '{$this->incident}', '{$this->sortBy}', {$this->pageStart}, {$this->perPage})";
     $res = $mysqli->multi_query("{$proc}; SELECT @allCount;");
     $this->lastUpdated = '0001-01-01 01:01:01';
     if ($res) {
         $results = 0;
         $c = 0;
         do {
             if ($result = $mysqli->store_result()) {
                 if ($c == 0) {
                     while ($row = $result->fetch_assoc()) {
                         $this->lastUpdated = $row["updated"];
                     }
                 }
                 $result->close();
                 if ($mysqli->more_results()) {
                     $c += 1;
                 }
             }
         } while ($mysqli->more_results() && $mysqli->next_result());
     }
     $mysqli->close();
     $date = new DateTime($this->lastUpdated);
     $this->lastUpdated = $date->format('Y-m-d H:i:s');
 }
Example #16
0
 public function multi_query($resource)
 {
     if (parent::multi_query($resource)) {
         do {
             if ($result = parent::store_result()) {
                 $result->free();
             }
             $this->queryCount++;
             if (!parent::more_results()) {
                 break;
             }
         } while (parent::next_result());
     }
     if ($this->errno) {
         throw new Exception("SQL Error: " . $this->error . "<br><br>Query Code: " . $resource);
     }
 }
Example #17
0
 /**
  * Execute multiple querries!
  *
  */
 function executeMultipleQuerries($query, $lastId = false)
 {
     # execute querries
     //$result = parent::multi_query($query);
     if ($result = parent::multi_query($query)) {
         do {
             /* store first result set */
             if ($result = parent::store_result()) {
                 $result->free();
             }
         } while (parent::next_result());
     }
     # save lastid
     $this->lastSqlId = $this->insert_id;
     # if it failes throw new exception
     if (mysqli_error($this)) {
         throw new exception(mysqli_error($this), mysqli_errno($this));
     } else {
         if ($lastId) {
             return $this->lastSqlId;
         } else {
             return true;
         }
     }
 }
 /**
  * restoreFromSql
  *
  * @param  string $sqlfile
  *
  * @return boolean false or true
  */
 function restoreFromSql($sqlfile, $type = 'file')
 {
     ini_set('memory_limit', '64M');
     if ($type == 'file' && !is_file($sqlfile)) {
         throw new Exception("the {$sqlfile} doesn't exist!");
     }
     $metaFile = str_replace('.sql', '.meta', $sqlfile);
     $queries = 0;
     if (is_file($metaFile)) {
         echo "Using {$metaFile} as metadata.\n";
         $fp = fopen($sqlfile, 'rb');
         $fpmd = fopen($metaFile, 'r');
         while ($offset = fgets($fpmd, 1024)) {
             $buffer = intval($offset);
             //reading the size of $oData
             $query = fread($fp, $buffer);
             //reading string $oData
             $queries += 1;
             if (!@mysql_query($query)) {
                 echo mysql_error() . "\n";
                 echo "==>" . $query . "<==\n";
             }
         }
     } else {
         $queries = NULL;
         try {
             $mysqli = new mysqli($this->host, $this->user, $this->passwd, $this->dbName);
             /* check connection */
             if (mysqli_connect_errno()) {
                 printf("Connect failed: %s\n", mysqli_connect_error());
                 exit;
             }
             if ($type == 'file') {
                 $query = file_get_contents($sqlfile);
             } else {
                 if ($type == 'string') {
                     $query = $sqlfile;
                 } else {
                     return false;
                 }
             }
             if (trim($query) == "") {
                 return false;
             }
             /* execute multi query */
             if ($mysqli->multi_query($query)) {
                 do {
                     /* store first result set */
                     if ($result = $mysqli->store_result()) {
                         while ($row = $result->fetch_row()) {
                             //printf("%s\n", $row[0]);
                         }
                         $result->free();
                     }
                     /* print divider */
                     if ($mysqli->more_results()) {
                         //printf("-----------------\n");
                     }
                 } while ($mysqli->next_result());
             } else {
                 throw new Exception(mysqli_error($mysqli));
             }
             /* close connection */
             $mysqli->close();
         } catch (Exception $e) {
             echo $query;
             echo $e->getMessage();
         }
     }
     return $queries;
 }
Example #19
0
    if ($server->select_db('phpback') === TRUE) {
        exit_error("ERROR #5: You already have a phpback database, please create another manually");
    }
    if (!$server->query("CREATE DATABASE IF NOT EXISTS phpback")) {
        exit_error("ERROR #6: Could not create database");
    }
    if ($server->select_db('phpback') === FALSE) {
        exit_error("ERROR #5: Generated database connection error");
    }
    $sql = file_get_contents('database_tables.sql');
    if ($server->multi_query($sql) === FALSE) {
        exit_error("ERROR #4: Couldn't create the tables");
    }
}
do {
    if ($r = $server->store_result()) {
        $r->free();
    }
} while ($server->more_results() && $server->next_result());
$result = $server->query("SELECT id FROM settings WHERE name='title'");
if ($result->num_rows == 1) {
    if (!@chmod('../install', 0777)) {
        echo "PLEASE DELETE install/ FOLDER MANUALLY. THEN GO TO yourwebsite.com/feedback/admin/ TO LOG IN.";
        exit;
    }
    unlink('index.php');
    unlink('install1.php');
    unlink('database_tables.sql');
    unlink('index2.php');
    unlink('install2.php');
    header('Location: ../admin');
Example #20
0
 function callMySQLIProcedure($sql)
 {
     $mysqli = new mysqli(XOOPS_DB_HOST, XOOPS_DB_USER, XOOPS_DB_PASS, XOOPS_DB_NAME);
     $mysqli->real_query($sql);
     $result = $mysqli->store_result();
     $row = $result->fetch_assoc();
     $status = $row['status'];
     $mysqli->close();
     return $status;
 }
Example #21
0
 /**
  * get array of multiple results
  *
  * returns multi-dimensional array
  *     first dimension is number
  *     from second on the values
  * 
  * if nothing is provided use assocciative results
  *
  */
 function getMultipleResults($query)
 {
     /* execute query */
     $result = parent::multi_query($query);
     /**
      * get results to array
      * first save it, than get each row from result and store it to active[]
      */
     do {
         $results = parent::store_result();
         /* save each to array (only first field) */
         while ($row = $results->fetch_row()) {
             $rows[] = $row[0];
         }
         $results->free();
     } while (parent::next_result());
     /* return result array of rows */
     return $rows;
     /* free result */
     $result->close();
 }
Example #22
0
 public function multi_query($resource)
 {
     $Timer = microtime(true);
     if (parent::multi_query($resource)) {
         do {
             if ($result = parent::store_result()) {
                 $result->free();
             }
             $this->queryCount++;
             if (!parent::more_results()) {
                 break;
             }
         } while (parent::next_result());
     }
     $this->SQL[] = $resource;
     if ($this->errno) {
         if ($this->exception == true) {
             throw new Exception("SQL Error: " . $this->error . "<br><br>Query Code: " . $resource);
         } else {
             return "SQL Error: " . $this->error;
         }
     }
 }
Example #23
0
function batch_query($server_cfg, $game_cfg, $queries)
{
    $combined_query = implode(";", $queries);
    error_log($combined_query . "\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name']));
    try {
        $db = new mysqli($game_cfg["db_host"], $game_cfg["db_user"], $game_cfg["db_pass"], $game_cfg["db_name"]);
        if (!$db->multi_query(implode(";", $queries))) {
            error_log("Failed!", 3, sprintf($server_cfg['log_file'], $game_cfg['name']));
            $db->close();
            return 1;
        }
        do {
            if ($result = $db->store_result()) {
                while ($row = $result->fetch_row()) {
                    printf("%s\n", $row[0]);
                }
                $result->free();
            }
        } while ($db->next_result());
        if ($db->errno) {
            error_log("Stopped while retrieving result : ", 3, sprintf($server_cfg['log_file'], $game_cfg['name']));
            $db->close();
            return 1;
        }
        $db->close();
    } catch (Exception $e) {
        error_log("Error in setting up mysqli multi-query:" . $e->getMessage() . " \n", 3, sprintf($server_cfg['log_file'], $game_cfg['name']));
        return 1;
    }
    return 0;
}
Example #24
0
 /** 
  * Run a query on a database object, returning the result
  *
  * @param mysqli $databaseObj A database object to run the query on.
  * @param string $query The query to run.
  * @return mixed An array of results if query is successful, or null on error.
  */
 private function __runQuery($databaseObj, $query)
 {
     $results = array();
     if ($databaseObj->multi_query($query)) {
         do {
             if ($result = $databaseObj->store_result()) {
                 array_push($results, $result->fetch_all(MYSQLI_ASSOC));
                 $result->free();
             }
             if (!$databaseObj->more_results()) {
                 break;
             }
             $databaseObj->next_result();
         } while (true);
         // If we only ran one query and got one result
         // just return that
         if (count($results) == 1) {
             return $results[0];
         }
         return $results;
     } else {
         if ($databaseObj->error) {
             $this->__logMessage(sprintf('Error: Query - %s failed with message - %s', $query, $databaseObj->error));
         }
     }
     return null;
 }
Example #25
0
 public function dowithByLPid($lotyid, $playid)
 {
     if (empty($lotyid) || empty($playid)) {
         $servers = $this->input->server('argv');
         $playid = $servers[3];
         $lotyid = $servers[2];
     }
     $databasic = array();
     $data = array();
     //得到玩法下的所有启用状态的自动跟单JOB
     $all_plan = $this->getAllPlan($lotyid, $playid);
     foreach ($all_plan as $aplanObj) {
         $aplan = $aplanObj->as_array();
         $auto_roder_jobs = $this->getAllJob($lotyid, $playid, $aplan['user_id']);
         foreach ($auto_roder_jobs as $aJobObj) {
             //处理该自动跟单
             $ajob = $aJobObj->as_array();
             $jobid = $ajob['id'];
             $uid = $ajob['uid'];
             $fuid = $ajob['fuid'];
             switch ($lotyid) {
                 case '1':
                     $pordernum = $aplan['basic_id'];
                     $this->plans_obj = $this->jczq_obj;
                     break;
                 case '2':
                     $pordernum = $aplan['basic_id'];
                     $this->plans_obj = $this->sfc_obj;
                     break;
                 case '6':
                     $pordernum = $aplan['basic_id'];
                     $this->plans_obj = $this->jclq_obj;
                     break;
                 case '7':
                     $pordernum = $aplan['basic_id'];
                     $this->plans_obj = $this->bjdc_obj;
                     break;
                 default:
                     $pordernum = $aplan['order_num'];
                     break;
             }
             $pid = $aplan['id'];
             $iscontinue = $this->log->where(array('pid' => $pid, 'uid' => $uid))->find()->as_array();
             if ($iscontinue['id']) {
                 continue;
             }
             //竞彩足球   其它彩种还要扩展这里
             $result = $this->plans_obj->get_by_order_id($pordernum);
             switch ($lotyid) {
                 case 2:
                     $result['surplus'] = $result['buyed'];
                     $result['buyed'] = $result['copies'] - $result['surplus'];
                     break;
             }
             $errcode = '200';
             //验证余额
             $userobj = user::get_instance();
             $usermoney = $userobj->get_user_money($uid);
             if ($usermoney < $ajob['money']) {
                 $errcode = '101';
                 //用户余额不足
             }
             //验证是否满员
             if ($result['surplus'] <= 0) {
                 $errcode = '102';
                 //'此方案已满员无法购买!';
             }
             //验证可认够的钱是否够
             if ($result['surplus'] * $result['price_one'] < $ajob['money']) {
                 $errcode = '103';
                 //方案可购金额小于你的订制金额
             }
             //方案是否限定范围
             if ($ajob['limitswitch']) {
                 if ($ajob['maximum'] < $result['total_price']) {
                     $errcode = '104';
                     //方案金额大于你的限定金额最大值
                 }
                 if ($ajob['minimum'] > $result['total_price']) {
                     $errcode = '105';
                     //方案金额小于你的限定金额的最小值
                 }
             }
             //检查方案日期是否结束
             if (strtotime($result['time_end']) < time()) {
                 $errcode = '106';
                 //'此方案已到期无法购买!';
             }
             //检查是否是合买对象
             if (!empty($result['friends']) && $result['friends'] != 'all') {
                 $errcode = '107';
                 //'此方案只有固定的彩友可以合买!';
             }
             $config = Kohana::config('database.default');
             extract($config['connection']);
             $mysqli = new mysqli($host, $user, $pass, $database, $port);
             if (mysqli_connect_errno()) {
                 echo '数据异常!';
             }
             $mysqli->query("SET NAMES 'utf8'");
             if ($errcode == '200') {
                 //					echo 'ssss';
                 $query = "call auto_order('" . $jobid . "','" . $pid . "','" . $lotyid . "','" . $playid . "')";
                 //echo $query;
                 if ($mysqli->multi_query($query)) {
                     do {
                         if ($rest = $mysqli->store_result()) {
                             while ($row = $rest->fetch_row()) {
                                 if ($row[0] != '200') {
                                     $sql = "INSERT INTO `auto_order_logs` (`lotyid`,`playid`, `fuid`, `funame`, `uid`, `uname`, `rgmoney`, `state`,\r\n\t\t\t\t\t`isuccess`, `errcode`,\t`ctime`, `ordernum`, `pid`)\r\n\t\t\t\t\tVALUES\t('" . $lotyid . "', '" . $playid . "','" . $fuid . "','" . $ajob['funame'] . "','" . $uid . "','" . $ajob['uname'] . "',0, '1','0', '" . $errcode . "',NOW(), '" . $pordernum . "', " . $pid . ");";
                                     $mysqli->query($sql);
                                 } else {
                                     if ($row[1] == 100) {
                                         //扯分彩票存入彩票表,打印彩票的格式/更新状态
                                         $this->plans_obj->get_tickets($pid, $result['play_method'], $result['codes'], $result['typename'], $result['special_num'], $result['rate'], $result['basic_id']);
                                         //更新方案状态为未出票(是父类的方案)
                                         $this->plans_obj->update_status($pid, 1);
                                     }
                                 }
                             }
                             $rest->close();
                         }
                     } while ($mysqli->next_result());
                 }
             } else {
                 $sql = "INSERT INTO `auto_order_logs` (`lotyid`,`playid`, `fuid`, `funame`, `uid`, `uname`, `rgmoney`, `state`,\r\n\t\t\t\t\t`isuccess`, `errcode`,\t`ctime`, `ordernum`, `pid`)\r\n\t\t\t\t\tVALUES\t('" . $lotyid . "', '" . $playid . "','" . $fuid . "','" . $ajob['funame'] . "','" . $uid . "','" . $ajob['uname'] . "',0, '1','0', '" . $errcode . "',NOW(), '" . $pordernum . "', " . $pid . ");";
                 //echo $sql;
                 $mysqli->query($sql);
             }
         }
     }
 }
Example #26
0
	FROM
		new_foogler_Comment
	WHERE
		comment_idPost = '{$messageId}';
EOD;

$query .= "SELECT username, name FROM new_foogler_User;";
$query .= "SELECT idPost, messageTitle, post_username FROM new_foogler_Post
			ORDER BY messageDate DESC
			LIMIT 10;";


$res = $mysqli->multi_query($query)
		or die('Could not query database');

$res = $mysqli->store_result()
		or die("Failed to retrive result from query."); 

//---------------------------------------------------------------------------------------------
//
//    the content of the page
//



$messages = "";

$row = $res->fetch_object();

if(isset($_SESSION['accountUser']) && $_SESSION['accountUser'] == $row->username) {
	$user = <<< EOD
Example #27
0
	function sp_exec($siteConfig, $exec)
	{	
		$mysqli = new mysqli( $siteConfig['server'],$siteConfig['user'],$siteConfig['pass'], $siteConfig['db']); 
		$mysqli->set_charset('utf-8');
		$ivalue=1; 
		if ($mysqli->multi_query($exec)) 
			if ($result = $mysqli->store_result()) 
				return $this->formati($result, $mysqli);			
		$mysqli->close();
	}
 public function printDSS($id, $year)
 {
     $config = new Config();
     $mysqli = new mysqli($config->host, $config->user, $config->pass, $config->db);
     if ($mysqli->connect_errno) {
         print json_encode(array('success' => false, 'status' => 400, 'msg' => 'Failed to connect to MySQL: (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error));
         return;
     } else {
         $data = array();
         if (strlen($id) == 2) {
             $var = str_split($id);
             $query1 = "SET @rank=0; SELECT A.* ,@rank:=@rank+1 AS rank FROM (SELECT l.id,l.name,l.description,l.landarea,(SELECT COUNT(c.id) FROM child c WHERE c.status_id IN ('{$var['0']}','{$var['1']}') AND c.locationID=l.id AND c.year_id={$year}) AS Count FROM location l GROUP BY l.id ORDER BY Count DESC) AS A WHERE A.Count > 0 LIMIT 5;";
             if ($result1 = $mysqli->multi_query($query1)) {
                 do {
                     if ($result1 = $mysqli->store_result()) {
                         while ($row = $result1->fetch_array(MYSQLI_ASSOC)) {
                             array_push($data, $row);
                         }
                         $result1->free();
                     }
                 } while ($mysqli->next_result());
             }
             return print json_encode(array('success' => true, 'status' => 200, 'data' => $data), JSON_PRETTY_PRINT);
         } else {
             $query1 = "CALL printDSS({$id},{$year})";
             $result1 = $mysqli->query($query1);
             while ($row = $result1->fetch_array(MYSQLI_ASSOC)) {
                 array_push($data, $row);
             }
             return print json_encode(array('success' => true, 'status' => 200, 'data' => $data), JSON_PRETTY_PRINT);
         }
     }
 }
			<br>
			<input type="submit" value="Submit">
</form>

<?php 
$mysqli = new mysqli("dbase.cs.jhu.edu", "cs41515_jsham2", "PTIASBIT", "cs41515_jsham2_db");
if (mysqli_connect_errno()) {
    printf("Connect failed: %s<br>", mysqli_connect_error());
    exit;
}
session_start();
$email = $_SESSION["email_addr"];
if ($mysqli->multi_query("CALL FindFilmsGivenEmail('" . $email . "');")) {
    printf("<table><tr><th>Film Name</th><th>Year</th><th>Rating</th><th>Genre</th><th>Country</th><th>Language</th><th>Budget</th><th>Gross</th></tr>");
    do {
        if ($result = $mysqli->store_result()) {
            while ($row = $result->fetch_row()) {
                printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>", $row[0], $row[1], $row[2], $row[3], $row[4], $row[5], $row[6], $row[7]);
            }
            $result->close();
        }
    } while ($mysqli->next_result());
    printf("</table>");
} else {
    printf("No results");
}
exit;
?>

</body>
</html>
Example #30
0
 /**
  * Executes the specified stored procedure.
  *
  * @param string $procedure The stored procedure to call
  * 
  * @return array $data The data from the stored procedure or FALSE if an error occured
  **/
 function executeStoredProcedure($procedure)
 {
     $mysqli = new mysqli(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, MYSQL_PORT);
     if (mysqli_connect_errno()) {
         // an error occured
         // printf("Connect failed: %s\n", mysqli_connect_error());
         $this->error_msg = printf("An error occured while connecting to the database, please try again later %s\n", mysqli_connect_error());
         return false;
     }
     # check that the stored procedure includes the word CALL
     if (substr(strtolower($procedure), 0, 4) != "call") {
         # error occured
         $this->error_msg = "The query for the stored procedure must include the CALL keyword";
         return false;
     }
     // execute the stored procedure
     // returns true if the query was sucessful
     //check if the query was successful
     if ($mysqli->multi_query($procedure)) {
         // check if the result is an instance of the resultset class
         if ($result = $mysqli->store_result()) {
             // do nothing
             //free the resultset
             $result->close();
         }
         //clear the other result(s) from buffer
         //loop through each result using the next_result() method
         while ($mysqli->next_result()) {
             //free each result.
             $result = $mysqli->use_result();
             $result->close();
         }
         $mysqli->close();
         return true;
     } else {
         // error occured
         $this->error_msg = "An error occured while updating the database, please try again later " . $mysqli->error;
         # TODO: Log the query and error message
         $mysqli->close();
         return false;
     }
 }