1--TEST--
2Calling connect() on an open persistent connection to create a new persistent connection
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
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    $link = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
38
39    if (true !== ($tmp = $link->real_connect($host, $user, $passwd, $db, $port, $socket)))
40        printf("[009] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp);
41
42    /* it is undefined which pooled connection we get - thread ids may differ */
43
44    if (!($res = $link->query("SELECT 'works also with oo' AS syntax")) ||
45            !($row = $res->fetch_assoc()))
46        printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
47
48    var_dump($row);
49    mysqli_free_result($res);
50
51    mysqli_close($link);
52
53    if (true !== ($tmp = $link->connect($host, $user, $passwd, $db, $port, $socket)))
54        printf("[013] Expecting true got %s/%s\n", gettype($tmp), $tmp);
55
56    if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket))
57        printf("[014] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
58            $host, $user, $db, $port, $socket);
59
60    if (true !== ($tmp = $link->connect($host, $user, $passwd, $db, $port, $socket)))
61        printf("[015] Expecting true got %s/%s\n", gettype($tmp), $tmp);
62
63    print "done!";
64?>
65--EXPECT--
66array(1) {
67  ["it_works"]=>
68  string(2) "ok"
69}
70array(1) {
71  ["syntax"]=>
72  string(18) "works also with oo"
73}
74done!
75