1--TEST--
2Calling connect() on an open persistent connection to create a new persistent connection
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
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	if (!$link = new my_mysqli($phost, $user, $passwd, $db, $port, $socket))
45		printf("[007] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
46			$phost, $user, $db, $port, $socket);
47
48	if (!$thread_id = $link->thread_id)
49		printf("[008] Cannot determine thread id, test will fail, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
50
51	if (true !== ($tmp = $link->real_connect($host, $user, $passwd, $db, $port, $socket)))
52		printf("[009] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp);
53
54	if (!is_int($new_thread_id = $link->thread_id) || ($new_thread_id < 0))
55		printf("[010] Expecting int/any got %s/%s\n", gettype($tmp), $tmp);
56
57	if ($thread_id == $new_thread_id)
58		printf("[011] Expecting new connection and new thread id. Old thread id %d, new thread id %d\n", $thread_id, $new_thread_id);
59
60	if (!($res = $link->query("SELECT 'works also with oo' AS syntax")) ||
61			!($row = $res->fetch_assoc()))
62		printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
63
64	var_dump($row);
65	mysqli_free_result($res);
66
67	mysqli_close($link);
68
69	if (NULL !== ($tmp = $link->connect($phost, $user, $passwd, $db, $port, $socket)))
70		printf("[013] Expecting NULL got %s/%s\n", gettype($tmp), $tmp);
71
72	if (!$link = mysqli_connect($phost, $user, $passwd, $db, $port, $socket))
73		printf("[014] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
74			$phost, $user, $db, $port, $socket);
75
76	if (NULL !== ($tmp = $link->connect($host, $user, $passwd, $db, $port, $socket)))
77		printf("[015] Expecting NULL got %s/%s\n", gettype($tmp), $tmp);
78
79	printf("Flipping phost/host order\n");
80
81		if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
82		printf("[016] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
83			$host, $user, $db, $port, $socket);
84
85	if (!$thread_id = mysqli_thread_id($link))
86		printf("[017] Cannot determine thread id, test will fail, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
87
88	if (true !== ($tmp = my_mysqli_real_connect($link, $phost, $user, $passwd, $db, $port, $socket)))
89		printf("[018] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp);
90
91	if (!is_int($new_thread_id = mysqli_thread_id($link)) || ($new_thread_id < 0))
92		printf("[019] Expecting int/any got %s/%s\n", gettype($tmp), $tmp);
93
94	if ($thread_id == $new_thread_id)
95		printf("[020] Expecting new connection and new thread id. Old thread id %d, new thread id %d\n", $thread_id, $new_thread_id);
96
97	if (!($res = mysqli_query($link, "SELECT 'ok' AS it_works")) ||
98		!($row = mysqli_fetch_assoc($res)))
99		printf("[021] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
100
101	var_dump($row);
102	mysqli_free_result($res);
103
104	mysqli_close($link);
105
106	if (!$link = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
107		printf("[022] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
108			$host, $user, $db, $port, $socket);
109
110	if (!$thread_id = $link->thread_id)
111		printf("[023] Cannot determine thread id, test will fail, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
112
113	if (true !== ($tmp = $link->real_connect($phost, $user, $passwd, $db, $port, $socket)))
114		printf("[024] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp);
115
116	if (!is_int($new_thread_id = $link->thread_id) || ($new_thread_id < 0))
117		printf("[025] Expecting int/any got %s/%s\n", gettype($tmp), $tmp);
118
119	if ($thread_id == $new_thread_id)
120		printf("[026] Expecting new connection and new thread id. Old thread id %d, new thread id %d\n", $thread_id, $new_thread_id);
121
122	if (!($res = $link->query("SELECT 'works also with oo' AS syntax")) ||
123			!($row = $res->fetch_assoc()))
124		printf("[027] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
125
126	var_dump($row);
127	mysqli_free_result($res);
128
129	mysqli_close($link);
130
131	if (NULL !== ($tmp = $link->connect($host, $user, $passwd, $db, $port, $socket)))
132		printf("[028] Expecting NULL got %s/%s\n", gettype($tmp), $tmp);
133
134	if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket))
135		printf("[029] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
136			$host, $user, $db, $port, $socket);
137
138	if (NULL !== ($tmp = $link->connect($phost, $user, $passwd, $db, $port, $socket)))
139		printf("[030] Expecting NULL got %s/%s\n", gettype($tmp), $tmp);
140
141	print "done!";
142?>
143--EXPECTF--
144array(1) {
145  [%u|b%"it_works"]=>
146  %unicode|string%(2) "ok"
147}
148array(1) {
149  [%u|b%"syntax"]=>
150  %unicode|string%(18) "works also with oo"
151}
152Flipping phost/host order
153array(1) {
154  [%u|b%"it_works"]=>
155  %unicode|string%(2) "ok"
156}
157array(1) {
158  [%u|b%"syntax"]=>
159  %unicode|string%(18) "works also with oo"
160}
161done!
162