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