|
| 1 | +--TEST-- |
| 2 | +mysqli.local_infile_directory vs access allowed |
| 3 | +--SKIPIF-- |
| 4 | +<?php |
| 5 | +require_once('skipif.inc'); |
| 6 | +require_once('skipifconnectfailure.inc'); |
| 7 | + |
| 8 | +if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) |
| 9 | + die("skip Cannot connect to MySQL"); |
| 10 | + |
| 11 | +include_once("local_infile_tools.inc"); |
| 12 | +if ($msg = check_local_infile_allowed_by_server($link)) |
| 13 | + die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); |
| 14 | + |
| 15 | +mysqli_close($link); |
| 16 | + |
| 17 | +?> |
| 18 | +--INI-- |
| 19 | +open_basedir={PWD} |
| 20 | +mysqli.allow_local_infile=0 |
| 21 | +mysqli.local_infile_directory={PWD}/foo |
| 22 | +--FILE-- |
| 23 | +<?php |
| 24 | + require_once("connect.inc"); |
| 25 | + |
| 26 | + if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { |
| 27 | + printf("[001] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); |
| 28 | + } |
| 29 | + |
| 30 | + if (!$link->query("DROP TABLE IF EXISTS test")) { |
| 31 | + printf("[002] [%d] %s\n", $link->errno, $link->error); |
| 32 | + } |
| 33 | + |
| 34 | + if (!$link->query("CREATE TABLE test (id INT UNSIGNED NOT NULL PRIMARY KEY) ENGINE=" . $engine)) { |
| 35 | + printf("[003] [%d] %s\n", $link->errno, $link->error); |
| 36 | + } |
| 37 | + |
| 38 | + $filepath = str_replace('\\', '/', __DIR__.'/foo/foo.data'); |
| 39 | + if (!$link->query("LOAD DATA LOCAL INFILE '".$filepath."' INTO TABLE test")) { |
| 40 | + printf("[004] [%d] %s\n", $link->errno, $link->error); |
| 41 | + } |
| 42 | + |
| 43 | + $filepath = str_replace('\\', '/', __DIR__.'/foo/bar/bar.data'); |
| 44 | + if (!$link->query("LOAD DATA LOCAL INFILE '".$filepath."' INTO TABLE test")) { |
| 45 | + printf("[005] [%d] %s\n", $link->errno, $link->error); |
| 46 | + } |
| 47 | + |
| 48 | + if ($res = mysqli_query($link, 'SELECT COUNT(id) AS num FROM test')) { |
| 49 | + $row = mysqli_fetch_assoc($res); |
| 50 | + mysqli_free_result($res); |
| 51 | + |
| 52 | + $row_count = $row['num']; |
| 53 | + $expected_row_count = 6; |
| 54 | + if ($row_count != $expected_row_count) { |
| 55 | + printf("[006] %d != %d\n", $row_count, $expected_row_count); |
| 56 | + } |
| 57 | + } else { |
| 58 | + printf("[007] [%d] %s\n", $link->errno, $link->error); |
| 59 | + } |
| 60 | + |
| 61 | + $link->close(); |
| 62 | + echo "done"; |
| 63 | +?> |
| 64 | +--CLEAN-- |
| 65 | +<?php |
| 66 | +require_once('connect.inc'); |
| 67 | + |
| 68 | +if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { |
| 69 | + printf("[clean] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", |
| 70 | + $host, $user, $db, $port, $socket); |
| 71 | +} |
| 72 | + |
| 73 | +if (!$link->query($link, 'DROP TABLE IF EXISTS test')) { |
| 74 | + printf("[clean] Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link)); |
| 75 | +} |
| 76 | + |
| 77 | +$link->close(); |
| 78 | +?> |
| 79 | +--EXPECT-- |
| 80 | +done |
0 commit comments