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