xref: /PHP-5.3/ext/mysql/tests/bug48754.phpt (revision 8aae3baa)
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
71Expect same thread id for $link and default conn: bool(true)
72resource(%d) of type (mysql link)
73resource(%d) of type (Unknown)
74
75Warning: mysql_close(): no MySQL-Link resource supplied in %s on line %d
76
77Closing default link
78Expect same thread id for $link and default conn but not the previous: bool(true)
79resource(%d) of type (mysql link)
80resource(%d) of type (mysql link)
81resource(%d) of type (Unknown)
82
83Explicit resource and pconnect
84resource(%d) of type (mysql link persistent)
85resource(%d) of type (Unknown)
86
87Warning: mysql_close(): no MySQL-Link resource supplied in %s on line %d
88
89Default link and pconnect
90resource(%d) of type (mysql link persistent)
91resource(%d) of type (mysql link persistent)
92resource(%d) of type (Unknown)
93