1--TEST-- 2mysql_query(LOAD DATA LOCAL INFILE) with large data set (10MB) 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifconnectfailure.inc'); 7 8$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket); 9if (!$link) 10 die(sprintf("skip Can't connect [%d] %s", mysqli_connect_errno(), mysqli_connect_error())); 11 12include_once("local_infile_tools.inc"); 13if ($msg = check_local_infile_support($link, $engine)) 14 die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); 15 16mysqli_close($link); 17?> 18--INI-- 19mysqli.allow_local_infile=1 20--FILE-- 21<?php 22 // Create a large CVS file 23 $file = tempnam(sys_get_temp_dir(), 'mysqli_test.cvs'); 24 if (!$fp = fopen($file, 'w')) 25 printf("[001] Cannot create CVS file '%s'\n", $file); 26 27 $data = str_repeat("a", 127) . ";" . str_repeat("b", 127) . "\n"; 28 29 $runtime = 5; 30 $max_bytes = 1024 * 1024 * 10; 31 32 $start = microtime(true); 33 $bytes = 0; 34 $rowno = 0; 35 while (($bytes < $max_bytes) && ((microtime(true) - $start) < $runtime)) { 36 if ((version_compare(PHP_VERSION, '5.9.9', '>') == 1)) 37 $bytes += fwrite($fp, (binary)(++$rowno . ";" . $data)); 38 else 39 $bytes += fwrite($fp, ++$rowno . ";" . $data); 40 } 41 fclose($fp); 42 printf("Filesize in bytes: %d\nRows: %d\n", $bytes, $rowno); 43 44 require_once("connect.inc"); 45 if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) 46 printf("[002] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); 47 48 if (!mysqli_query($link, "DROP TABLE IF EXISTS test") || 49 !mysqli_query($link, "CREATE TABLE test(id INT, col1 VARCHAR(255), col2 VARCHAR(255)) ENGINE = " . $engine)) 50 printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 51 52 if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s' INTO TABLE test FIELDS TERMINATED BY ';'", mysqli_real_escape_string($link, $file)))) 53 printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 54 55 if ((!is_string(mysqli_info($link))) || ('' == mysqli_info($link))) { 56 printf("[005] [%d] %s, mysqli_info not set \n", mysqli_errno($link), mysqli_error($link)); 57 } 58 59 if (!($res = mysqli_query($link, "SELECT COUNT(*) AS _num FROM test"))) 60 printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 61 62 $row = mysqli_fetch_assoc($res); 63 if (($row["_num"] != $rowno)) 64 printf("[007] Expecting %d rows, found %d\n", $rowno, $row["_num"]); 65 66 mysqli_free_result($res); 67 68 $random = mt_rand(1, $rowno); 69 if (!$res = mysqli_query($link, "SELECT id, col1, col2 FROM test WHERE id = " . $random)) 70 printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 71 72 $row = mysqli_fetch_assoc($res); 73 var_dump($row); 74 mysqli_free_result($res); 75 76 mysqli_close($link); 77 print "done!"; 78?> 79--CLEAN-- 80<?php 81$file = tempnam(sys_get_temp_dir(), 'mysqli_test.cvs'); 82if (file_exists($file)) 83 unlink($file); 84 85require_once("connect.inc"); 86if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) 87 printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); 88 89if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) 90 printf("[c002] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 91?> 92--EXPECTF-- 93Filesize in bytes: %d 94Rows: %d 95array(3) { 96 [%u|b%"id"]=> 97 %unicode|string%(%d) "%d" 98 [%u|b%"col1"]=> 99 %unicode|string%(127) "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 100 [%u|b%"col2"]=> 101 %unicode|string%(127) "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" 102} 103done!