1--TEST-- 2LOAD DATA INFILE - open_basedir 3--SKIPIF-- 4<?php 5include_once('skipif.inc'); 6 7if (!isset($db)) { 8 die("skip open_basedir setting prevents inclusing of required files"); 9} 10 11include_once('skipifconnectfailure.inc'); 12 13 14if (!$IS_MYSQLND) 15 die("skip mysqlnd only, libmysql does not know about open_basedir restrictions"); 16 17if (file_exists('./simple.csv') && !unlink('./simple.csv')) 18 die("skip Cannot remove previous CSV file"); 19 20if (!$fp = fopen('./simple.csv', 'w')) 21 die("skip Cannot create test CSV file"); 22 23fclose($fp); 24@unlink('./simple.csv'); 25 26if ($socket == "" && $host != NULL && $host != 'localhost' && $host != '.') { 27 /* could be a remote TCP/IP connection. LOCAL INFILE may not work */ 28 if (gethostbyaddr($host) != gethostname()) { 29 die("skip LOAD DATA LOCAL INFILE will fail if connecting to remote MySQL"); 30 } 31} 32?> 33--INI-- 34open_basedir="." 35--FILE-- 36<?php 37@include_once("connect.inc"); 38 39if (!isset($db)) { 40 // run-tests, I love you for not allowing me to set ini settings dynamically 41 print "[006] [1148] The used command is not allowed with this MySQL version 42[007] [0] 43[008] LOAD DATA not run? 44[010] [1148] The used command is not allowed with this MySQL version 45done!"; 46 die(); 47} 48require('table.inc'); 49mysql_close($link); 50if ($socket) 51 $host = sprintf("%s:%s", $host, $socket); 52else if ($port) 53 $host = sprintf("%s:%s", $host, $port); 54 55if (!$link = mysql_connect($host, $user, $passwd, true, 128)) { 56 printf("[001] Cannot connect using host '%s', user '%s', password '****', [%d] %s\n", 57 $host, $user, $passwd, 58 mysql_errno(), mysql_error()); 59} 60 61if (!mysql_select_db($db, $link)) { 62 printf("[002] [%d] %s\n", mysql_errno($link), mysql_error($link)); 63} 64 65if (file_exists('./simple.csv')) 66 unlink('./simple.csv'); 67 68if (!$fp = fopen('./simple.csv', 'w')) 69 printf("[003] Cannot open CSV file\n"); 70 71if (version_compare(PHP_VERSION, '5.9.9', '>') >= 0) { 72 if (!fwrite($fp, (binary)"'97';'x';\n") || 73 !fwrite($fp, (binary)"'98';'y';\n") || 74 !fwrite($fp, (binary)"99;'z';\n")) { 75 printf("[004] Cannot write CVS file '%s'\n", $file); 76 } 77} else { 78 if (!fwrite($fp, "97;'x';\n") || 79 !fwrite($fp, "98;'y';\n") || 80 !fwrite($fp, "99;'z';\n")) { 81 printf("[005] Cannot write CVS file '%s'\n", $file); 82 } 83} 84fclose($fp); 85 86$sql = sprintf("LOAD DATA LOCAL INFILE '%s' 87 INTO TABLE test 88 FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\'' 89 LINES TERMINATED BY '\n'", 90 mysql_real_escape_string(realpath('./simple.csv'), $link)); 91 92if (!mysql_query($sql, $link)) 93 printf("[006] [%d] %s\n", mysql_errno($link), mysql_error($link)); 94 95if (!($res = mysql_query('SELECT label FROM test WHERE id = 97', $link)) || 96 !($row = mysql_fetch_assoc($res)) || 97 !mysql_free_result($res)) 98 printf("[007] [%d] '%s'\n", mysql_errno($link), mysql_error($link)); 99 100if ($row['label'] != "x") 101 printf("[008] LOAD DATA not run?\n"); 102 103if (!mysql_query('DELETE FROM test', $link)) 104 printf("[009] [%d] %s\n", mysql_errno($link), mysql_error($link)); 105 106$sql = "LOAD DATA LOCAL INFILE '/tmp/idonotexist' 107 INTO TABLE test 108 FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\'' 109 LINES TERMINATED BY '\n'"; 110 111if (!mysql_query($sql, $link)) 112 printf("[010] [%d] %s\n", mysql_errno($link), mysql_error($link)); 113 114mysql_close($link); 115unlink("./simple.csv"); 116 117print "done!"; 118?> 119--EXPECTF-- 120[006] [1148] %s 121[007] [0] '' 122[008] LOAD DATA not run? 123[010] [1148] %s 124done! 125