1--TEST-- 2mysql_[p]connect() - max_links/max_persistent 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifconnectfailure.inc'); 7require_once('table.inc'); 8 9mysql_query('DROP USER pcontest', $link); 10if (!mysql_query('CREATE USER pcontest IDENTIFIED BY "pcontest"', $link)) { 11 printf("skip Cannot create second DB user [%d] %s", mysql_errno($link), mysql_error($link)); 12 mysql_close($link); 13 die(); 14} 15 16// we might be able to specify the host using CURRENT_USER(), but... 17if (!mysql_query(sprintf("GRANT SELECT ON TABLE %s.test TO pcontest@'%%'", $db), $link)) { 18 printf("skip Cannot GRANT SELECT to second DB user [%d] %s", mysql_errno($link), mysql_error($link)); 19 mysql_query('REVOKE ALL PRIVILEGES, GRANT OPTION FROM pcontest', $link); 20 mysql_query('DROP USER pcontest', $link); 21 mysql_close($link); 22 die(); 23} 24mysql_close($link); 25?> 26--INI-- 27mysql.max_links=2 28mysql.allow_persistent=1 29mysql.max_persistent=1 30--FILE-- 31<?php 32require_once('connect.inc'); 33 34function my_connect($offset, $host, $user, $passwd, $db, $port, $socket) { 35 if ($socket) 36 $host = sprintf("%s:%s", $host, $socket); 37 else if ($port) 38 $host = sprintf("%s:%s", $host, $port); 39 40 41 $link = mysql_pconnect($host, $user, $passwd); 42 if (!$link) { 43 printf("[%03d] Cannot connect using host '%s', user '%s', password '****', [%d] %s\n", 44 $offset, $host, $user, $passwd, 45 mysql_errno(), mysql_error()); 46 return false; 47 } 48 49 if (!mysql_select_db($db, $link)) 50 return false; 51 52 return $link; 53} 54 55$links = array(); 56 57// try to open 2 links 58$links[0] = my_connect(10, $host, $user, $passwd, $db, $port, $socket); 59$links[1] = my_connect(20, $host, 'pcontest', 'pcontest', $db, $port, $socket); 60if (false !== $links[1]) 61 printf("[030] Last connection should not have been allowed!\n"); 62 63// free some links but let index 1 remain 64unset($links[1]); 65mysql_close($links[0]); 66unset($links[0]); 67 68// should be allowed -> only open connection 69$links[0] = my_connect(40, $host, $user, $passwd, $db, $port, $socket); 70var_dump($links); 71 72mysql_query('REVOKE ALL PRIVILEGES, GRANT OPTION FROM pcontest', $links[0]); 73mysql_query('DROP USER pcontest', $links[0]); 74 75mysql_close($links[0]); 76print "done!\n"; 77?> 78--CLEAN-- 79<?php 80// connect + select_db 81require_once("connect.inc"); 82if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket)) { 83 printf("[c001] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 84 $host, $myhost, $user, $db, $port, $socket); 85} 86 87@mysql_query('REVOKE ALL PRIVILEGES, GRANT OPTION FROM pcontest', $link); 88@mysql_query('DROP USER pcontest', $link); 89 90mysql_close($link); 91?> 92--EXPECTF-- 93Deprecated: mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d 94 95Deprecated: mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d 96 97Warning: mysql_pconnect(): Too many open persistent links (1) in %s on line %d 98[020] Cannot connect using host '%s', user '%s', password '****', [0] 0 99 100Deprecated: mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d 101array(1) { 102 [0]=> 103 resource(%d) of type (mysql link persistent) 104} 105done! 106