type == 1 when mysqlnd and unbuffered queries i.e. with use result // $result->type == 0 when not mysqlnd and buffered queries i.e. without use result if(extension_loaded('mysqlnd') && !empty($result->type)){ $return = (int) (!empty($result)); }elseif(extension_loaded('mysqli')){ $return = @mysqli_num_rows($result); }else{ $return = @mysql_num_rows($result); } return $return; } function soft_mysql_fetch_assoc($result){ // If $result is not a resource return else it will lead to FATAL error if(empty($result)){ return false; } if(extension_loaded('mysqli')){ $return = @mysqli_fetch_assoc($result); }else{ $return = @mysql_fetch_assoc($result); } return $return; } function softdie($txt, $query = 0, $x = 0){ $array = array(); $array['settings'] = $GLOBALS['settings']; $array['result'] = $txt; if(!empty($query)){ $array['query_no'] = $query; } // Was there an error ? if(!empty($GLOBALS['error'])){ $array['error'] = $GLOBALS['error']; } // Return the SELECT statement if(!empty($GLOBALS['return'])){ $array['return'] = $GLOBALS['return']; } echo ''.base64_encode(serialize($array)).''; if($x < 1){ die(); } } // Give the response in 20 seconds ! $end = (int) (time() + 20); // The settings $settings = unserialize(base64_decode('[[[settings]]]')); // The QUERIES $queries = unserialize(base64_decode('[[[queries]]]')); /*echo '
';
print_r($return);
print_r($settings);
print_r($queries);
echo '
';*/ $host = $settings['softdbhost']; $user = $settings['softdbuser']; $pass = $settings['softdbpass']; $db = $settings['softdb']; //Make the Connection $__conn = @soft_mysql_connect($host, $user, $pass, true); //CHECK Errors and SELECT DATABASE if(!empty($__conn)){ if(!(@soft_mysql_select_db($db, $__conn))){ softdie('seldb'); } }else{ softdie('conn'); } // Total number of queries $num = count($queries); // Query Number to start from $nquery = 0; if(!empty($_GET['nquery'])){ //Next query to be executed, if this has to be continued from where we left last time. $nquery = $_GET['nquery']; } // SET MYSQL VARIABLES EACH TIME WE EXEC QUERIES. We are doing this as we are breaking queries. if(!empty($nquery)){ $mysql_var = array(); $mysql_var[] = 'SET @OLD_TIME_ZONE=@@TIME_ZONE;'; $mysql_var[] = 'SET time_zone = "+00:00";'; $mysql_var[] = 'SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT;'; $mysql_var[] = 'SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS;'; $mysql_var[] = 'SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;'; $mysql_var[] = 'SET NAMES utf8mb4'; $mysql_var[] = 'SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;'; $mysql_var[] = 'SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;'; $mysql_var[] = 'SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE="NO_AUTO_VALUE_ON_ZERO";'; $mysql_var[] = 'SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0;'; $mysql_var[] = 'SET @saved_cs_client=@@character_set_client;'; foreach($mysql_var as $mk => $mq){ //PARSE the String and make the QUERY $result = soft_mysql_query($mq, $__conn); //Looks like there was an error if(!$result){ $error['k'] = $mk; $error['q'] = $mq; $error['errno'] = soft_mysql_errno($__conn); $error['errstr'] = soft_mysql_error($__conn); softdie('query'); } } } //Start the Queries foreach($queries as $k => $q){ // Don't do anything if the queries are already executed. if($k < $nquery){ continue; } // Current time. $progress = (int) time(); // Give response if the time is up and pass the next query. if($progress >= $end){ softdie('INCOMPLETE', $k); } //PARSE the String and make the QUERY $result = soft_mysql_query($q, $__conn); //Looks like there was an error if(!$result){ $error['k'] = $k; $error['q'] = $q; $error['errno'] = soft_mysql_errno($__conn); $error['errstr'] = soft_mysql_error($__conn); softdie('query'); } // Is there only one query ? if($num == 1){ // Is it a SELECT query ? if(preg_match('/^(SELECT|SHOW|DESCRIBE)/is', $q)){ // Accumulate the data ! if(soft_mysql_num_rows($result) > 0){ while($row = soft_mysql_fetch_assoc($result)){ $return[] = $row; } } } } } // Delete the file in the end. @unlink(__FILE__); softdie('DONE'); echo '
';
print_r($return);
print_r($settings);
print_r($queries);
echo '
';