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('skipifconnectfailure.inc'); 7?> 8--INI-- 9mysqli.allow_persistent=1 10mysqli.max_persistent=-1 11mysqli.max_links=-1 12--FILE-- 13<?php 14 require_once("connect.inc"); 15 16 $phost = 'p:' . $host; 17 18 if (!$link = my_mysqli_connect($phost, $user, $passwd, $db, $port, $socket)) 19 printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 20 $phost, $user, $db, $port, $socket); 21 22 if (!$thread_id = $link->thread_id) 23 printf("[002] Cannot determine thread id, test will fail, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 24 25 if (true !== ($tmp = my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket))) 26 printf("[003] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp); 27 28 if (!is_int($new_thread_id = mysqli_thread_id($link)) || ($new_thread_id < 0)) 29 printf("[004] Expecting int/any got %s/%s\n", gettype($tmp), $tmp); 30 31 if ($thread_id == $new_thread_id) 32 printf("[005] Expecting new connection and new thread id. Old thread id %d, new thread id %d\n", $thread_id, $new_thread_id); 33 34 if (!($res = mysqli_query($link, "SELECT 'ok' AS it_works")) || 35 !($row = mysqli_fetch_assoc($res))) 36 printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 37 38 var_dump($row); 39 mysqli_free_result($res); 40 41 mysqli_close($link); 42 43 if (!$link = new my_mysqli($phost, $user, $passwd, $db, $port, $socket)) 44 printf("[007] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 45 $phost, $user, $db, $port, $socket); 46 47 if (!$thread_id = $link->thread_id) 48 printf("[008] Cannot determine thread id, test will fail, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 49 50 if (true !== ($tmp = $link->real_connect($host, $user, $passwd, $db, $port, $socket))) 51 printf("[009] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp); 52 53 if (!is_int($new_thread_id = $link->thread_id) || ($new_thread_id < 0)) 54 printf("[010] Expecting int/any got %s/%s\n", gettype($tmp), $tmp); 55 56 if ($thread_id == $new_thread_id) 57 printf("[011] Expecting new connection and new thread id. Old thread id %d, new thread id %d\n", $thread_id, $new_thread_id); 58 59 if (!($res = $link->query("SELECT 'works also with oo' AS syntax")) || 60 !($row = $res->fetch_assoc())) 61 printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 62 63 var_dump($row); 64 mysqli_free_result($res); 65 66 mysqli_close($link); 67 68 if (NULL !== ($tmp = $link->connect($phost, $user, $passwd, $db, $port, $socket))) 69 printf("[013] Expecting NULL got %s/%s\n", gettype($tmp), $tmp); 70 71 if (!$link = mysqli_connect($phost, $user, $passwd, $db, $port, $socket)) 72 printf("[014] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 73 $phost, $user, $db, $port, $socket); 74 75 if (NULL !== ($tmp = $link->connect($host, $user, $passwd, $db, $port, $socket))) 76 printf("[015] Expecting NULL got %s/%s\n", gettype($tmp), $tmp); 77 78 printf("Flipping phost/host order\n"); 79 80 if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) 81 printf("[016] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 82 $host, $user, $db, $port, $socket); 83 84 if (!$thread_id = mysqli_thread_id($link)) 85 printf("[017] Cannot determine thread id, test will fail, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 86 87 if (true !== ($tmp = my_mysqli_real_connect($link, $phost, $user, $passwd, $db, $port, $socket))) 88 printf("[018] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp); 89 90 if (!is_int($new_thread_id = mysqli_thread_id($link)) || ($new_thread_id < 0)) 91 printf("[019] Expecting int/any got %s/%s\n", gettype($tmp), $tmp); 92 93 if ($thread_id == $new_thread_id) 94 printf("[020] Expecting new connection and new thread id. Old thread id %d, new thread id %d\n", $thread_id, $new_thread_id); 95 96 if (!($res = mysqli_query($link, "SELECT 'ok' AS it_works")) || 97 !($row = mysqli_fetch_assoc($res))) 98 printf("[021] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 99 100 var_dump($row); 101 mysqli_free_result($res); 102 103 mysqli_close($link); 104 105 if (!$link = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) 106 printf("[022] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 107 $host, $user, $db, $port, $socket); 108 109 if (!$thread_id = $link->thread_id) 110 printf("[023] Cannot determine thread id, test will fail, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 111 112 if (true !== ($tmp = $link->real_connect($phost, $user, $passwd, $db, $port, $socket))) 113 printf("[024] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp); 114 115 if (!is_int($new_thread_id = $link->thread_id) || ($new_thread_id < 0)) 116 printf("[025] Expecting int/any got %s/%s\n", gettype($tmp), $tmp); 117 118 if ($thread_id == $new_thread_id) 119 printf("[026] Expecting new connection and new thread id. Old thread id %d, new thread id %d\n", $thread_id, $new_thread_id); 120 121 if (!($res = $link->query("SELECT 'works also with oo' AS syntax")) || 122 !($row = $res->fetch_assoc())) 123 printf("[027] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 124 125 var_dump($row); 126 mysqli_free_result($res); 127 128 mysqli_close($link); 129 130 if (NULL !== ($tmp = $link->connect($host, $user, $passwd, $db, $port, $socket))) 131 printf("[028] Expecting NULL got %s/%s\n", gettype($tmp), $tmp); 132 133 if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) 134 printf("[029] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 135 $host, $user, $db, $port, $socket); 136 137 if (NULL !== ($tmp = $link->connect($phost, $user, $passwd, $db, $port, $socket))) 138 printf("[030] Expecting NULL got %s/%s\n", gettype($tmp), $tmp); 139 140 print "done!"; 141?> 142--EXPECT-- 143array(1) { 144 ["it_works"]=> 145 string(2) "ok" 146} 147array(1) { 148 ["syntax"]=> 149 string(18) "works also with oo" 150} 151Flipping phost/host order 152array(1) { 153 ["it_works"]=> 154 string(2) "ok" 155} 156array(1) { 157 ["syntax"]=> 158 string(18) "works also with oo" 159} 160done! 161