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