xref: /PHP-5.5/ext/mysql/tests/bug48754.phpt (revision b7091aaf)
1--TEST--
2Bug #48754 (mysql_close() crash php when no handle specified)
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10require_once('connect.inc');
11
12function my_mysql_pconnect($host, $user, $passwd, $db, $port, $socket) {
13	if ($socket)
14		$host = sprintf("%s:%s", $host, $socket);
15	else if ($port)
16		$host = sprintf("%s:%s", $host, $port);
17
18	if (!$link = mysql_pconnect($host, $user, $passwd, true)) {
19		printf("[000-a] Cannot connect using host '%s', user '%s', password '****', [%d] %s\n",
20			$host, $user, $passwd,
21			mysql_errno(), mysql_error());
22		return false;
23	}
24	return $link;
25}
26
27echo "Explicit connection on close\n";
28$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket);
29$link1_thread_id = mysql_thread_id($link);
30$default1_thread_id = mysql_thread_id();
31echo 'Expect same thread id for $link and default conn: ';
32var_dump($link1_thread_id == $default1_thread_id);
33var_dump($link);
34mysql_close($link);
35var_dump($link);
36
37// we sohuld have no default link anymore
38mysql_close();
39
40echo "\nClosing default link\n";
41$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket);
42$link2_thread_id = mysql_thread_id($link);
43$default2_thread_id = mysql_thread_id();
44echo 'Expect same thread id for $link and default conn but not the previous: ';
45var_dump($link1_thread_id == $default1_thread_id && $link1_thread_id != $link2_thread_id);
46var_dump($link);
47mysql_close();
48var_dump($link);
49mysql_close($link);
50var_dump($link);
51
52echo "\nExplicit resource and pconnect\n";
53$link = my_mysql_pconnect($host, $user, $passwd, $db, $port, $socket);
54var_dump($link);
55mysql_close($link);
56var_dump($link);
57
58// we sohuld have no default link
59mysql_close();
60
61echo "\nDefault link and pconnect\n";
62$link = my_mysql_pconnect($host, $user, $passwd, $db, $port, $socket);
63var_dump($link);
64mysql_close();
65var_dump($link);
66mysql_close($link);
67var_dump($link);
68?>
69--EXPECTF--
70Explicit connection on close
71
72Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
73Expect same thread id for $link and default conn: bool(true)
74resource(%d) of type (mysql link)
75resource(%d) of type (Unknown)
76
77Warning: mysql_close(): no MySQL-Link resource supplied in %s on line %d
78
79Closing default link
80
81Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
82Expect same thread id for $link and default conn but not the previous: bool(true)
83resource(%d) of type (mysql link)
84resource(%d) of type (mysql link)
85resource(%d) of type (Unknown)
86
87Explicit resource and pconnect
88
89Deprecated: mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
90resource(%d) of type (mysql link persistent)
91resource(%d) of type (Unknown)
92
93Warning: mysql_close(): no MySQL-Link resource supplied in %s on line %d
94
95Default link and pconnect
96
97Deprecated: mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
98resource(%d) of type (mysql link persistent)
99resource(%d) of type (mysql link persistent)
100resource(%d) of type (Unknown)
101