1--TEST--
2Calling connect() on an open persistent connection to create a new persistent connection
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8?>
9--INI--
10mysqli.allow_persistent=1
11mysqli.max_persistent=-1
12mysqli.max_links=-1
13--FILE--
14<?php
15    require_once 'connect.inc';
16
17    $phost = 'p:' . $host;
18
19    if (!$link = my_mysqli_connect($phost, $user, $passwd, $db, $port, $socket))
20        printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
21            $phost, $user, $db, $port, $socket);
22
23    if (!$thread_id = $link->thread_id)
24        printf("[002] Cannot determine thread id, test will fail, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
25
26    if (true !== ($tmp = my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket)))
27        printf("[003] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp);
28
29    if (!is_int($new_thread_id = mysqli_thread_id($link)) || ($new_thread_id < 0))
30        printf("[004] Expecting int/any got %s/%s\n", gettype($tmp), $tmp);
31
32    if ($thread_id == $new_thread_id)
33        printf("[005] Expecting new connection and new thread id. Old thread id %d, new thread id %d\n", $thread_id, $new_thread_id);
34
35    if (!($res = mysqli_query($link, "SELECT 'ok' AS it_works")) ||
36        !($row = mysqli_fetch_assoc($res)))
37        printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
38
39    var_dump($row);
40    mysqli_free_result($res);
41
42    mysqli_close($link);
43
44    $link = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
45
46    if (!$thread_id = $link->thread_id)
47        printf("[008] Cannot determine thread id, test will fail, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
48
49    if (true !== ($tmp = $link->real_connect($host, $user, $passwd, $db, $port, $socket)))
50        printf("[009] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp);
51
52    if (!is_int($new_thread_id = $link->thread_id) || ($new_thread_id < 0))
53        printf("[010] Expecting int/any got %s/%s\n", gettype($tmp), $tmp);
54
55    if ($thread_id == $new_thread_id)
56        printf("[011] Expecting new connection and new thread id. Old thread id %d, new thread id %d\n", $thread_id, $new_thread_id);
57
58    if (!($res = $link->query("SELECT 'works also with oo' AS syntax")) ||
59            !($row = $res->fetch_assoc()))
60        printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
61
62    var_dump($row);
63    mysqli_free_result($res);
64
65    mysqli_close($link);
66
67    if (true !== ($tmp = $link->connect($phost, $user, $passwd, $db, $port, $socket)))
68        printf("[013] Expecting NULL got %s/%s\n", gettype($tmp), $tmp);
69
70    if (!$link = mysqli_connect($phost, $user, $passwd, $db, $port, $socket))
71        printf("[014] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
72            $phost, $user, $db, $port, $socket);
73
74    if (true !== ($tmp = $link->connect($host, $user, $passwd, $db, $port, $socket)))
75        printf("[015] Expecting true got %s/%s\n", gettype($tmp), $tmp);
76
77    printf("Flipping phost/host order\n");
78
79        if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
80        printf("[016] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
81            $host, $user, $db, $port, $socket);
82
83    if (!$thread_id = mysqli_thread_id($link))
84        printf("[017] Cannot determine thread id, test will fail, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
85
86    if (true !== ($tmp = my_mysqli_real_connect($link, $phost, $user, $passwd, $db, $port, $socket)))
87        printf("[018] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp);
88
89    if (!is_int($new_thread_id = mysqli_thread_id($link)) || ($new_thread_id < 0))
90        printf("[019] Expecting int/any got %s/%s\n", gettype($tmp), $tmp);
91
92    if ($thread_id == $new_thread_id)
93        printf("[020] Expecting new connection and new thread id. Old thread id %d, new thread id %d\n", $thread_id, $new_thread_id);
94
95    if (!($res = mysqli_query($link, "SELECT 'ok' AS it_works")) ||
96        !($row = mysqli_fetch_assoc($res)))
97        printf("[021] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
98
99    var_dump($row);
100    mysqli_free_result($res);
101
102    mysqli_close($link);
103
104    $link = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
105
106    if (!$thread_id = $link->thread_id)
107        printf("[023] Cannot determine thread id, test will fail, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
108
109    if (true !== ($tmp = $link->real_connect($phost, $user, $passwd, $db, $port, $socket)))
110        printf("[024] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp);
111
112    if (!is_int($new_thread_id = $link->thread_id) || ($new_thread_id < 0))
113        printf("[025] Expecting int/any got %s/%s\n", gettype($tmp), $tmp);
114
115    if ($thread_id == $new_thread_id)
116        printf("[026] Expecting new connection and new thread id. Old thread id %d, new thread id %d\n", $thread_id, $new_thread_id);
117
118    if (!($res = $link->query("SELECT 'works also with oo' AS syntax")) ||
119            !($row = $res->fetch_assoc()))
120        printf("[027] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
121
122    var_dump($row);
123    mysqli_free_result($res);
124
125    mysqli_close($link);
126
127    if (true !== ($tmp = $link->connect($host, $user, $passwd, $db, $port, $socket)))
128        printf("[028] Expecting true got %s/%s\n", gettype($tmp), $tmp);
129
130    if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket))
131        printf("[029] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
132            $host, $user, $db, $port, $socket);
133
134    if (true !== ($tmp = $link->connect($phost, $user, $passwd, $db, $port, $socket)))
135        printf("[030] Expecting true got %s/%s\n", gettype($tmp), $tmp);
136
137    print "done!";
138?>
139--EXPECT--
140array(1) {
141  ["it_works"]=>
142  string(2) "ok"
143}
144array(1) {
145  ["syntax"]=>
146  string(18) "works also with oo"
147}
148Flipping phost/host order
149array(1) {
150  ["it_works"]=>
151  string(2) "ok"
152}
153array(1) {
154  ["syntax"]=>
155  string(18) "works also with oo"
156}
157done!
158