1--TEST--
2Calling connect() on an open connection to create a new connection
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
7require_once('skipifconnectfailure.inc');
8?>
9--FILE--
10<?php
11	require_once("connect.inc");
12
13	if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
14		printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
15			$host, $user, $db, $port, $socket);
16
17	if (!$thread_id = mysqli_thread_id($link))
18		printf("[002] Cannot determine thread id, test will fail, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
19
20	if (true !== ($tmp = my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket)))
21		printf("[003] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp);
22
23	if (!is_int($new_thread_id = mysqli_thread_id($link)) || ($new_thread_id < 0))
24		printf("[004] Expecting int/any got %s/%s\n", gettype($tmp), $tmp);
25
26	if ($thread_id == $new_thread_id)
27		printf("[005] Expecting new connection and new thread id. Old thread id %d, new thread id %d\n", $thread_id, $new_thread_id);
28
29	if (!($res = mysqli_query($link, "SELECT 'ok' AS it_works")) ||
30		!($row = mysqli_fetch_assoc($res)))
31		printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
32
33	var_dump($row);
34	mysqli_free_result($res);
35
36	mysqli_close($link);
37
38	if (!$link = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
39		printf("[007] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
40			$host, $user, $db, $port, $socket);
41
42	if (!$thread_id = $link->thread_id)
43		printf("[008] Cannot determine thread id, test will fail, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
44
45	if (true !== ($tmp = $link->real_connect($host, $user, $passwd, $db, $port, $socket)))
46		printf("[009] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp);
47
48	if (!is_int($new_thread_id = $link->thread_id) || ($new_thread_id < 0))
49		printf("[010] Expecting int/any got %s/%s\n", gettype($tmp), $tmp);
50
51	if ($thread_id == $new_thread_id)
52		printf("[011] Expecting new connection and new thread id. Old thread id %d, new thread id %d\n", $thread_id, $new_thread_id);
53
54	if (!($res = $link->query("SELECT 'works also with oo' AS syntax")) ||
55			!($row = $res->fetch_assoc()))
56		printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
57
58	var_dump($row);
59	mysqli_free_result($res);
60
61	mysqli_close($link);
62
63	if (NULL !== ($tmp = $link->connect($host, $user, $passwd, $db, $port, $socket)))
64		printf("[013] Expecting NULL got %s/%s\n", gettype($tmp), $tmp);
65
66	if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket))
67		printf("[014] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
68			$host, $user, $db, $port, $socket);
69
70	if (NULL !== ($tmp = $link->connect($host, $user, $passwd, $db, $port, $socket)))
71		printf("[015] Expecting NULL got %s/%s\n", gettype($tmp), $tmp);
72
73	print "done!";
74?>
75--EXPECTF--
76array(1) {
77  [%u|b%"it_works"]=>
78  %unicode|string%(2) "ok"
79}
80array(1) {
81  [%u|b%"syntax"]=>
82  %unicode|string%(18) "works also with oo"
83}
84done!