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