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?>
10--INI--
11mysqli.allow_persistent=1
12mysqli.max_persistent=-1
13mysqli.max_links=-1
14--FILE--
15<?php
16	require_once("connect.inc");
17
18	$host = 'p:' . $host;
19	if (!$link = my_mysqli_connect($host, $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			$host, $user, $db, $port, $socket);
22
23	if (true !== ($tmp = my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket)))
24		printf("[003] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp);
25
26	/* it is undefined which pooled connection we get - thread ids may differ */
27
28	if (!($res = mysqli_query($link, "SELECT 'ok' AS it_works")) ||
29		!($row = mysqli_fetch_assoc($res)))
30		printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
31
32	var_dump($row);
33	mysqli_free_result($res);
34
35	mysqli_close($link);
36
37	if (!$link = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
38		printf("[007] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
39			$host, $user, $db, $port, $socket);
40
41
42	if (true !== ($tmp = $link->real_connect($host, $user, $passwd, $db, $port, $socket)))
43		printf("[009] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp);
44
45	/* it is undefined which pooled connection we get - thread ids may differ */
46
47	if (!($res = $link->query("SELECT 'works also with oo' AS syntax")) ||
48			!($row = $res->fetch_assoc()))
49		printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
50
51	var_dump($row);
52	mysqli_free_result($res);
53
54	mysqli_close($link);
55
56	if (NULL !== ($tmp = $link->connect($host, $user, $passwd, $db, $port, $socket)))
57		printf("[013] Expecting NULL got %s/%s\n", gettype($tmp), $tmp);
58
59	if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket))
60		printf("[014] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
61			$host, $user, $db, $port, $socket);
62
63	if (NULL !== ($tmp = $link->connect($host, $user, $passwd, $db, $port, $socket)))
64		printf("[015] Expecting NULL got %s/%s\n", gettype($tmp), $tmp);
65
66	print "done!";
67?>
68--EXPECT--
69array(1) {
70  ["it_works"]=>
71  string(2) "ok"
72}
73array(1) {
74  ["syntax"]=>
75  string(18) "works also with oo"
76}
77done!
78