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