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