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