[ create a new paste ] login | about

Link: http://codepad.org/WNxylU8G    [ raw code | output | fork ]

PHP, pasted on Dec 13:
<?php
ini_set('memory_limit', '92M');

// connect to MySQL 5.6
$mysqli = mysqli_init();
$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5);
@ $mysqli->real_connect('127.0.0.1', 'user', 'passwd', 'database', '3306');

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

// prepare dataset
$sql = "CREATE TABLE IF NOT EXISTS `Test` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `parentId` smallint(5) unsigned NOT NULL,
    `seoId` varchar(255) COLLATE utf8_czech_ci NOT NULL,
    `name` varchar(255) COLLATE utf8_czech_ci NOT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8";
$mysqli->query($sql);

$sql = "TRUNCATE `Test`";
$mysqli->query($sql);

$i = 0;
do {
	$sql = "INSERT INTO Test (parentId, seoId, name) VALUES " . str_repeat("(1, 'seoId', 'name'),", 1000);
	$i += 1000;
	$mysqli->query(rtrim($sql, ','));
} while ($i < 10000);

$sql = str_repeat("SELECT * FROM Test LIMIT 100; SELECT * FROM Test LIMIT 100;", 1000);

// read data by multiquery
$mysqli->multi_query($sql);
$retArr = array();
do {
	if ($res = $mysqli->store_result()) {
        	$ret = array();
            	while ($row = $res->fetch_assoc()) {
                	$ret[] = $row;
            	}
            	$res->free();
            	
                $retArr[] = $ret;
        }
} while ($mysqli->more_results() && $mysqli->next_result()); 


Output:
1
2

Fatal error: Call to undefined function mysqli_init() on line 5


Create a new paste based on this one


Comments: