1--TEST--
2PDO::MYSQL_ATTR_LOCAL_INFILE_DIRECTORY vs access denied
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
8MySQLPDOTest::skip();
9require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipifinfilenotallowed.inc');
10if (!defined('PDO::MYSQL_ATTR_LOCAL_INFILE_DIRECTORY')) {
11    die("skip No MYSQL_ATTR_LOCAL_INFILE_DIRECTORY support");
12}
13?>
14--FILE--
15<?php
16	function exec_and_count($offset, &$db, $sql, $exp) {
17		try {
18			$ret = $db->exec($sql);
19			if ($ret !== $exp) {
20				printf("[%03d] Expecting '%s'/%s got '%s'/%s when running '%s', [%s] %s\n",
21					$offset, $exp, gettype($exp), $ret, gettype($ret), $sql,
22					$db->errorCode(), implode(' ', $db->errorInfo()));
23				return false;
24			}
25		} catch (PDOException $e) {
26			printf("[%03d] '%s' has failed, [%s] %s\n",
27				$offset, $sql, $db->errorCode(), implode(' ', $db->errorInfo()));
28			return false;
29		}
30
31		return true;
32	}
33
34	require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
35	putenv('PDOTEST_ATTR='.serialize([
36		PDO::MYSQL_ATTR_LOCAL_INFILE=>false,
37		PDO::MYSQL_ATTR_LOCAL_INFILE_DIRECTORY=>__DIR__."/foo/bar"
38		]));
39	$db = MySQLPDOTest::factory();
40	MySQLPDOTest::createTestTable($db, MySQLPDOTest::detect_transactional_mysql_engine($db));
41
42	try {
43		exec_and_count(1, $db, 'DROP TABLE IF EXISTS test', 0);
44		exec_and_count(2, $db, sprintf('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, col1 CHAR(10)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE), 0);
45
46		$filepath = str_replace('\\', '/', __DIR__.'/foo/foo.data');
47
48		$sql = sprintf("LOAD DATA LOCAL INFILE %s INTO TABLE test FIELDS TERMINATED BY ';' LINES TERMINATED  BY '\n'", $db->quote($filepath));
49		if (exec_and_count(3, $db, $sql, false)) {
50			$stmt = $db->query('SELECT id, col1 FROM test ORDER BY id ASC');
51			$expected = array();
52			$ret = $stmt->fetchAll(PDO::FETCH_ASSOC);
53			if ($ret != $expected) {
54				printf("Results seem wrong, check manually\n");
55				echo "------ EXPECTED OUTPUT ------\n";
56				var_dump($expected);
57				echo "------ ACTUAL OUTPUT ------\n";
58				var_dump($ret);
59			}
60		}
61	} catch (PDOException $e) {
62		printf("[001] %s, [%s] %s\n",
63			$e->getMessage(),
64			$db->errorCode(), implode(' ', $db->errorInfo()));
65	}
66
67	print "done!";
68?>
69--CLEAN--
70<?php
71require dirname(__FILE__) . '/mysql_pdo_test.inc';
72$db = MySQLPDOTest::factory();
73$db->exec('DROP TABLE IF EXISTS test');
74?>
75--EXPECTF--
76Warning: PDO::exec(): SQLSTATE[HY000]: General error: 2068 LOAD DATA LOCAL INFILE %s in %s on line %d
77done!
78