1--TEST--
2new mysqli()
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8?>
9--FILE--
10<?php
11    require_once 'connect.inc';
12
13    if ($socket != "")
14        /* mysqli.default_socket requires non-empty string */
15        ini_set('mysqli.default_socket', 'socket');
16
17    ini_set('mysqli.default_port', 9999);
18    ini_set('mysqli.default_pw', 'password');
19    ini_set('mysqli.default_user', 'user');
20    ini_set('mysqli.default_host', 'host');
21
22    mysqli_report(MYSQLI_REPORT_OFF);
23    mysqli_report(MYSQLI_REPORT_STRICT);
24
25    if ($socket != "") {
26        ini_set('mysqli.default_socket', $socket);
27        try {
28            $mysqli = mysqli_init();
29            $mysqli->real_connect($host, $user, $passwd, $db, $port);
30
31            if (!$res = $mysqli->query("SELECT 'mysqli.default_socket' AS testing"))
32                printf("[001] [%d] %s\n", $mysqli->errno, $mysqli->error);
33            $tmp = $res->fetch_assoc();
34            $res->free_result();
35
36            if (!isset($tmp['testing']) || $tmp['testing'] != 'mysqli.default_socket') {
37                printf("[002] mysqli.default_socket not properly set?\n");
38                var_dump($tmp);
39            }
40
41            $mysqli->close();
42
43        } catch (mysqli_sql_exception $e) {
44            printf("%s\n", $e->getMessage());
45            printf("[002] Usage of mysqli.default_socket failed\n");
46        }
47    }
48
49    ini_set('mysqli.default_port', $port);
50    try {
51        $mysqli = mysqli_init();
52        $mysqli->real_connect($host, $user, $passwd, $db);
53
54        if (!$res = $mysqli->query("SELECT 'mysqli.default_port' AS testing"))
55            printf("[003] [%d] %s\n", $mysqli->errno, $mysqli->error);
56        var_dump($res->fetch_assoc());
57        $res->free_result();
58
59        $mysqli->close();
60
61    } catch (mysqli_sql_exception $e) {
62        printf("%s\n", $e->getMessage());
63        printf("[004] Usage of mysqli.default_port failed\n");
64    }
65
66    ini_set('mysqli.default_pw', $passwd);
67    try {
68        $mysqli = mysqli_init();
69        $mysqli->real_connect($host, $user);
70        $mysqli->select_db($db);
71
72        if (!$res = $mysqli->query("SELECT 'mysqli.default_pw' AS testing"))
73            printf("[005] [%d] %s\n", $mysqli->errno, $mysqli->error);
74        var_dump($res->fetch_assoc());
75        $res->free_result();
76
77        $mysqli->close();
78
79    } catch (mysqli_sql_exception $e) {
80        printf("%s\n", $e->getMessage());
81        printf("[006] Usage of mysqli.default_pw failed\n");
82    }
83
84    ini_set('mysqli.default_user', $user);
85    try {
86        $mysqli = mysqli_init();
87        $mysqli->real_connect($host);
88        $mysqli->select_db($db);
89
90        if (!$res = $mysqli->query("SELECT 'mysqli.default_user' AS testing"))
91            printf("[007] [%d] %s\n", $mysqli->errno, $mysqli->error);
92        var_dump($res->fetch_assoc());
93        $res->free_result();
94
95        $mysqli->close();
96
97    } catch (mysqli_sql_exception $e) {
98        printf("%s\n", $e->getMessage());
99        printf("[008] Usage of mysqli.default_user failed\n");
100    }
101
102    ini_set('mysqli.default_host', $host);
103    try {
104        $mysqli = mysqli_init();
105        $mysqli->real_connect();
106        $mysqli->select_db($db);
107
108        if (!$res = $mysqli->query("SELECT 1"))
109            printf("[009] [%d] %s\n", $mysqli->errno, $mysqli->error);
110        $res->free_result();
111
112        if (!$res = $mysqli->query("SELECT SUBSTRING_INDEX(USER(),'@',1) AS username"))
113            printf("[010] [%d] %s\n", $mysqli->errno, $mysqli->error);
114
115        $tmp = $res->fetch_assoc();
116        $res->free_result();
117        if ($tmp['username'] !== $user)
118            printf("[011] Expecting string/%s, got %s/%s\n", $user, gettype($tmp['username']), $tmp['username']);
119
120        $mysqli->close();
121
122    } catch (mysqli_sql_exception $e) {
123        printf("%s\n", $e->getMessage());
124        printf("[012] Usage of mysqli.default_host failed\n");
125    }
126
127    try {
128        $link = mysqli_connect($host, $user, $passwd, null, ini_get('mysqli.default_port'));
129        mysqli_select_db($link, $db);
130        if (!$res = mysqli_query($link, "SELECT 'have been set' AS all_defaults"))
131            printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
132        var_dump(mysqli_fetch_assoc($res));
133        mysqli_free_result($res);
134        mysqli_close($link);
135    } catch (mysqli_sql_exception $e) {
136        printf("%s\n", $e->getMessage());
137        printf("[014] Usage of mysqli_connect() has failed\n");
138    }
139
140    try {
141        $link = mysqli_connect($host, $user, $passwd, null);
142        mysqli_select_db($link, $db);
143        if (!$res = mysqli_query($link, "SELECT 'have been set' AS all_defaults"))
144            printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
145        var_dump(mysqli_fetch_assoc($res));
146        mysqli_free_result($res);
147        mysqli_close($link);
148    } catch (mysqli_sql_exception $e) {
149        printf("%s\n", $e->getMessage());
150        printf("[016] Usage of mysqli_connect() has failed\n");
151    }
152
153
154    print "done!";
155?>
156--EXPECT--
157array(1) {
158  ["testing"]=>
159  string(19) "mysqli.default_port"
160}
161array(1) {
162  ["testing"]=>
163  string(17) "mysqli.default_pw"
164}
165array(1) {
166  ["testing"]=>
167  string(19) "mysqli.default_user"
168}
169array(1) {
170  ["all_defaults"]=>
171  string(13) "have been set"
172}
173array(1) {
174  ["all_defaults"]=>
175  string(13) "have been set"
176}
177done!
178