Skip to content

Commit 0c21715

Browse files
committed
ext/mysqli: Remove conditional function declaration
1 parent 17a80eb commit 0c21715

File tree

1 file changed

+58
-64
lines changed

1 file changed

+58
-64
lines changed

ext/mysqli/tests/connect.inc

Lines changed: 58 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -25,83 +25,77 @@
2525
/* Development setting: test experimental features and/or feature requests that never worked before? */
2626
$TEST_EXPERIMENTAL = 1 == getenv("MYSQL_TEST_EXPERIMENTAL");
2727

28-
if (!function_exists('my_mysqli_connect')) {
29-
30-
/**
31-
* Whenever possible, please use this wrapper to make testing of MYSQLI_CLIENT_COMPRESS (and potentially SSL) possible
32-
*
33-
* @param bool $enable_env_flags Enable setting of connection flags through env(MYSQL_TEST_CONNECT_FLAGS)?
34-
*/
35-
function my_mysqli_connect($host, $user, $passwd, $db, $port, $socket, $enable_env_flags = true) {
36-
global $connect_flags;
37-
38-
$flags = $enable_env_flags? $connect_flags:0;
39-
if ($flags !== 0) {
40-
$link = mysqli_init();
41-
if (!mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, $flags))
42-
$link = false;
43-
} else {
44-
$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket);
45-
}
46-
47-
return $link;
28+
/**
29+
* Whenever possible, please use this wrapper to make testing of MYSQLI_CLIENT_COMPRESS (and potentially SSL) possible
30+
*
31+
* @param bool $enable_env_flags Enable setting of connection flags through env(MYSQL_TEST_CONNECT_FLAGS)?
32+
*/
33+
function my_mysqli_connect($host, $user, $passwd, $db, $port, $socket, $enable_env_flags = true) {
34+
global $connect_flags;
35+
36+
$flags = $enable_env_flags? $connect_flags:0;
37+
if ($flags !== 0) {
38+
$link = mysqli_init();
39+
if (!mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, $flags))
40+
$link = false;
41+
} else {
42+
$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket);
4843
}
4944

50-
/**
51-
* Whenever possible, please use this wrapper to make testing of MYSQLI_CLIENT_COMPRESS (and potentially SSL) possible
52-
*
53-
* @param bool $enable_env_flags Enable setting of connection flags through env(MYSQL_TEST_CONNECT_FLAGS)
54-
*/
55-
function my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, $flags = 0, $enable_env_flags = true) {
56-
global $connect_flags;
45+
return $link;
46+
}
5747

58-
if ($enable_env_flags)
59-
$flags = $flags | $connect_flags;
48+
/**
49+
* Whenever possible, please use this wrapper to make testing of MYSQLI_CLIENT_COMPRESS (and potentially SSL) possible
50+
*
51+
* @param bool $enable_env_flags Enable setting of connection flags through env(MYSQL_TEST_CONNECT_FLAGS)
52+
*/
53+
function my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, $flags = 0, $enable_env_flags = true) {
54+
global $connect_flags;
6055

61-
return mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, $flags);
62-
}
56+
if ($enable_env_flags)
57+
$flags = $flags | $connect_flags;
6358

64-
class my_mysqli extends mysqli {
65-
public function __construct($host, $user, $passwd, $db, $port, $socket, $enable_env_flags = true) {
66-
global $connect_flags;
59+
return mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, $flags);
60+
}
6761

68-
$flags = ($enable_env_flags) ? $connect_flags : 0;
62+
class my_mysqli extends mysqli {
63+
public function __construct($host, $user, $passwd, $db, $port, $socket, $enable_env_flags = true) {
64+
global $connect_flags;
6965

70-
if ($flags !== 0) {
71-
parent::__construct();
72-
$this->real_connect($host, $user, $passwd, $db, $port, $socket, $flags);
73-
} else {
74-
parent::__construct($host, $user, $passwd, $db, $port, $socket);
75-
}
66+
$flags = ($enable_env_flags) ? $connect_flags : 0;
67+
68+
if ($flags !== 0) {
69+
parent::__construct();
70+
$this->real_connect($host, $user, $passwd, $db, $port, $socket, $flags);
71+
} else {
72+
parent::__construct($host, $user, $passwd, $db, $port, $socket);
7673
}
7774
}
75+
}
7876

79-
function have_innodb($link) {
80-
if (($res = $link->query("SHOW VARIABLES LIKE 'have_innodb'"))
81-
&& ($row = $res->fetch_row())
82-
&& !empty($row)
83-
) {
84-
return !($row[1] == 'DISABLED' || $row[1] == 'NO');
85-
}
86-
// MySQL 5.6.1+
87-
if ($res = $link->query('SHOW ENGINES')) {
88-
while ($row = $res->fetch_assoc()) {
89-
if (!isset($row['Engine']) || !isset($row['Support'])) {
90-
return false;
91-
}
92-
93-
if (($row['Engine'] == 'InnoDB')
94-
&& (($row['Support'] == 'YES') || ($row['Support'] == 'DEFAULT'))
95-
) {
96-
return true;
97-
}
77+
function have_innodb($link) {
78+
if (($res = $link->query("SHOW VARIABLES LIKE 'have_innodb'"))
79+
&& ($row = $res->fetch_row())
80+
&& !empty($row)
81+
) {
82+
return !($row[1] == 'DISABLED' || $row[1] == 'NO');
83+
}
84+
// MySQL 5.6.1+
85+
if ($res = $link->query('SHOW ENGINES')) {
86+
while ($row = $res->fetch_assoc()) {
87+
if (!isset($row['Engine']) || !isset($row['Support'])) {
88+
return false;
89+
}
90+
91+
if (($row['Engine'] == 'InnoDB')
92+
&& (($row['Support'] == 'YES') || ($row['Support'] == 'DEFAULT'))
93+
) {
94+
return true;
9895
}
9996
}
100-
return false;
10197
}
102-
103-
} else {
104-
printf("skip Eeeek/BUG/FIXME - connect.inc included twice! skipif bug?\n");
98+
return false;
10599
}
106100

107101
function handle_catchable_fatal($errno, $error, $file, $line) {

0 commit comments

Comments
 (0)