Skip to content

Commit

Permalink
Remove some mysql extension assertions
Browse files Browse the repository at this point in the history
Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed May 15, 2020
1 parent 3463257 commit fcd41f6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 48 deletions.
22 changes: 3 additions & 19 deletions libraries/classes/Config/Validator.php
Expand Up @@ -225,31 +225,15 @@ public static function testDBConnection(

error_clear_last();

if (DatabaseInterface::checkDbExtension('mysqli')) {
$socket = empty($socket) ? null : $socket;
$port = empty($port) ? null : $port;
$extension = 'mysqli';
} else {
$socket = empty($socket) ? null : ':' . ($socket[0] == '/' ? '' : '/') . $socket;
$port = empty($port) ? null : ':' . $port;
$extension = 'mysql';
}
$socket = empty($socket) ? null : $socket;
$port = empty($port) ? null : $port;

if ($extension == 'mysql') {
$conn = @mysql_connect($host . $port . $socket, $user, $pass);
if (! $conn) {
$error = __('Could not connect to the database server!');
} else {
mysql_close($conn);
}
} else {
$conn = @mysqli_connect($host, $user, $pass, null, $port, $socket);
$conn = @mysqli_connect($host, $user, $pass, null, $port, $socket);
if (! $conn) {
$error = __('Could not connect to the database server!');
} else {
mysqli_close($conn);
}
}
if ($error !== null) {
$lastError = error_get_last();
if ($lastError !== null) {
Expand Down
15 changes: 0 additions & 15 deletions libraries/classes/Database/Routines.php
Expand Up @@ -126,21 +126,6 @@ public function main($type)
'has_privilege' => Util::currentUserHasPrivilege('CREATE ROUTINE', $db, $table),
]);

/**
* Display a warning for users with PHP's old "mysql" extension.
*/
if (! DatabaseInterface::checkDbExtension('mysqli')) {
trigger_error(
__(
'You are using PHP\'s deprecated \'mysql\' extension, '
. 'which is not capable of handling multi queries. '
. '[strong]The execution of some stored routines may fail![/strong] '
. 'Please use the improved \'mysqli\' extension to '
. 'avoid any problems.'
),
E_USER_WARNING
);
}
}

/**
Expand Down
12 changes: 1 addition & 11 deletions libraries/classes/DatabaseInterface.php
Expand Up @@ -152,16 +152,6 @@ public function __construct(DbiExtension $ext)
$this->relation = new Relation($this);
}

/**
* Checks whether database extension is loaded
*
* @param string $extension mysql extension to check
*/
public static function checkDbExtension(string $extension = 'mysqli'): bool
{
return function_exists($extension . '_connect');
}

/**
* runs a query
*
Expand Down Expand Up @@ -3161,7 +3151,7 @@ public static function load(?DbiExtension $extension = null): self
return new self($extension);
}

if (! self::checkDbExtension('mysqli')) {
if (! Util::checkDbExtension('mysqli')) {
$docUrl = MySQLDocumentation::getDocumentationLink('faq', 'faqmysql');
$docLink = sprintf(
__('See %sour documentation%s for more information.'),
Expand Down
14 changes: 11 additions & 3 deletions libraries/classes/Util.php
Expand Up @@ -2937,6 +2937,16 @@ public static function getTablesWhenOpen($db, $db_info_result)
return $tables;
}

/**
* Checks whether database extension is loaded
*
* @param string $extension mysql extension to check
*/
public static function checkDbExtension(string $extension = 'mysqli'): bool
{
return function_exists($extension . '_connect');
}

/**
* Returs list of used PHP extensions.
*
Expand All @@ -2945,10 +2955,8 @@ public static function getTablesWhenOpen($db, $db_info_result)
public static function listPHPExtensions()
{
$result = [];
if (DatabaseInterface::checkDbExtension('mysqli')) {
if (Util::checkDbExtension('mysqli')) {
$result[] = 'mysqli';
} else {
$result[] = 'mysql';
}

if (extension_loaded('curl')) {
Expand Down

0 comments on commit fcd41f6

Please sign in to comment.