Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header('Content-type: text/html; charset=utf-8');
- // header('Content-type: text/plain; charset=utf-8');
- ini_set("display_errors", 1);
- ini_set("track_errors", 1);
- ini_set("html_errors", 1);
- ini_set("realpath_cache_size", '5M');
- ini_set('max_execution_time', 9999999900000);
- error_reporting(E_ALL);
- define('_USER_', 'username');
- define('_PASSWD_', 'password');
- define('_DB_', 'database');
- global $mysqli;
- $mysqli = new mysqli('localhost', _USER_, _PASSWD_, _DB_);
- $timeStart = microtime_float();
- $mysqli->query('SELECT * FROM schema.table');
- $timeEnd = microtime_float();
- $time = $timeEnd - $timeStart;
- echo PHP_EOL . "Execution time : $time";
- echo PHP_EOL . '--- END ---';
- die();
- /**
- * Execute an array of sql for updating base
- * @return nothing
- */
- function executeArray($allSql)
- {
- global $mysqli;
- if ($mysqli->connect_errno) {
- echo "<br>----------------------------";
- echo "<br>Sorry, first try connect_errno.";
- }
- foreach ($allSql as $key => $sql) {
- if (!$result = $mysqli->query($sql)) {
- echo "<br>----------------------------";
- echo " <br>Sorry, here the problem:";
- echo " <br>Query: " . $sql ;
- echo " <br>Errno: " . $mysqli->errno ;
- echo " <br>Error: " . $mysqli->error ;
- exit;
- }
- }
- return true;
- }
- /**
- * Execute an SQL, and return an result array
- * @return array of int
- */
- function executeS($sql)
- {
- global $mysqli;
- if ($mysqli->connect_errno) {
- echo "<br>----------------------------";
- echo "<br>Sorry, first try connect_errno.";
- }
- if (!$result = $mysqli->query($sql)) {
- echo "<br>----------------------------";
- echo " <br>Sorry, here the problem:";
- echo " <br>Query: " . $sql ;
- echo " <br>Errno: " . $mysqli->errno ;
- echo " <br>Error: " . $mysqli->error ;
- exit;
- }
- $rows = array();
- while ($row = $result->fetch_assoc()) {
- array_push($rows, $row);
- }
- return $rows;
- }
- /**
- * Execute only one sql for the setting of base eg ALTER ...
- * @return nothing
- */
- function executeOne($sql)
- {
- global $mysqli;
- if ($mysqli->connect_errno) {
- echo "<br>----------------------------";
- echo "<br>Sorry, first try connect_errno.";
- }
- if (!$result = $mysqli->query($sql)) {
- echo "<br>----------------------------";
- echo " <br>Sorry, here the problem:";
- echo " <br>Query: " . $sql ;
- echo " <br>Errno: " . $mysqli->errno ;
- echo " <br>Error: " . $mysqli->error ;
- exit;
- }
- return true;
- ;
- }
- function microtime_float()
- {
- list($usec, $sec) = explode(" ", microtime());
- return ((float)$usec + (float)$sec);
- }
- /**
- * Execute an SQL, and return an result array
- * @return array of int
- */
- function getValue($sql)
- {
- $result = connectAndExecuteSQL($sql);
- $rows = array();
- while ($row = $result->fetch_assoc()) {
- array_push($rows, $row);
- }
- return $rows;
- }
- function connectAndExecuteSQL($sql, $is_array = null)
- {
- global $mysqli;
- if ($mysqli->connect_errno) {
- echo "<br>----------------------------";
- echo "<br>Sorry, first try connect_errno.";
- }
- if (!$result = $mysqli->query($sql)) {
- echo "<br>----------------------------";
- echo " <br>Sorry, here the problem:";
- echo " <br>Query: " . $sql ;
- echo " <br>Errno: " . $mysqli->errno ;
- echo " <br>Error: " . $mysqli->error ;
- exit;
- }
- return $mysqli;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement