Annotation of embedaddon/php/ext/mysql/tests/mysql_query_load_data_openbasedir.phpt, revision 1.1.1.3

1.1       misho       1: --TEST--
                      2: LOAD DATA INFILE - open_basedir
                      3: --SKIPIF--
                      4: <?php
                      5: include_once('skipif.inc');
                      6: include_once('skipifconnectfailure.inc');
                      7: 
                      8: 
                      9: if (!$IS_MYSQLND)
                     10:        die("skip mysqlnd only, libmysql does not know about open_basedir restrictions");
                     11: 
                     12: if (file_exists('./simple.csv') && !unlink('./simple.csv'))
                     13:        die("skip Cannot remove previous CSV file");
                     14: 
                     15: if (!$fp = fopen('./simple.csv', 'w'))
                     16:        die("skip Cannot create test CSV file");
                     17: 
                     18: fclose($fp);
                     19: @unlink('./simple.csv');
                     20: 
                     21: if ($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");
1.1.1.2   misho      31: ini_set("open_basedir", __DIR__);
                     32: chdir(__DIR__);
1.1       misho      33: if (!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
                     39: done!";
                     40:        die();
                     41: }
                     42: require('table.inc');
                     43: mysql_close($link);
                     44: if ($socket)
                     45:        $host = sprintf("%s:%s", $host, $socket);
                     46: else if ($port)
                     47:        $host = sprintf("%s:%s", $host, $port);
                     48: 
                     49: if (!$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: 
                     55: if (!mysql_select_db($db, $link)) {
                     56:        printf("[002] [%d] %s\n", mysql_errno($link), mysql_error($link));
                     57: }
                     58: 
                     59: if (file_exists('./simple.csv'))
                     60:        unlink('./simple.csv');
                     61: 
                     62: if (!$fp = fopen('./simple.csv', 'w'))
                     63:        printf("[003] Cannot open CSV file\n");
                     64: 
                     65: if (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: }
                     78: fclose($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: 
                     86: if (!mysql_query($sql, $link))
                     87:        printf("[006] [%d] %s\n", mysql_errno($link), mysql_error($link));
                     88: 
                     89: if (!($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: 
                     94: if ($row['label'] != "x")
                     95:        printf("[008] LOAD DATA not run?\n");
                     96: 
                     97: if (!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: 
                    105: if (!mysql_query($sql, $link))
                    106:        printf("[010] [%d] %s\n", mysql_errno($link), mysql_error($link));
                    107: 
                    108: mysql_close($link);
                    109: unlink("./simple.csv");
                    110: 
                    111: print "done!";
                    112: ?>
                    113: --EXPECTF--
                    114: [006] [1148] %s
                    115: [007] [0] ''
                    116: [008] LOAD DATA not run?
                    117: [010] [1148] %s
                    118: done!

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>