xref: /PHP-8.2/ext/mysqli/tests/bug77956.phpt (revision 05ed3b77)
1--TEST--
2ensure an error is returned when mysqli.allow_local_infile is off
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once 'connect.inc';
8
9$link = mysqli_init();
10if (!@my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket)) {
11    die(sprintf("skip Can't connect to MySQL Server - [%d] %s", mysqli_connect_errno(), mysqli_connect_error()));
12}
13
14include_once "local_infile_tools.inc";
15if ($msg = check_local_infile_support($link, $engine))
16    die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error));
17
18mysqli_close($link);
19?>
20--INI--
21mysqli.allow_local_infile=0
22--FILE--
23<?php
24    require_once("connect.inc");
25    if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
26        printf("[001] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
27    }
28    if (!$link->query("DROP TABLE IF EXISTS test")) {
29        printf("[002] [%d] %s\n", $link->errno, $link->error);
30    }
31    if (!$link->query("CREATE TABLE test (dump1 INT UNSIGNED NOT NULL PRIMARY KEY) ENGINE=" . $engine)) {
32        printf("[003] [%d] %s\n", $link->errno, $link->error);
33    }
34    if (FALSE == file_put_contents('bug77956.data', "waa? meukee!"))
35        printf("[004] Failed to create CVS file\n");
36    if (!$link->query("SELECT 1 FROM DUAL"))
37        printf("[005] [%d] %s\n", $link->errno, $link->error);
38    if (!$link->query("LOAD DATA LOCAL INFILE 'bug77956.data' INTO TABLE test")) {
39        printf("[006] [%d] %s\n", $link->errno, $link->error);
40        echo "done";
41    } else {
42        echo "bug";
43    }
44    $link->close();
45?>
46--CLEAN--
47<?php
48require_once('connect.inc');
49if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
50	printf("[clean] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
51		$host, $user, $db, $port, $socket);
52}
53if (!$link->query('DROP TABLE IF EXISTS test')) {
54	printf("[clean] Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
55}
56$link->close();
57unlink('bug77956.data');
58?>
59--EXPECT--
60[006] [2000] LOAD DATA LOCAL INFILE is forbidden, check related settings like mysqli.allow_local_infile|mysqli.local_infile_directory or PDO::MYSQL_ATTR_LOCAL_INFILE|PDO::MYSQL_ATTR_LOCAL_INFILE_DIRECTORY
61done
62