mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #11383 from wilr/features/9394-mysqli-flags
feat: support defining MySQLi flags
This commit is contained in:
commit
c7ba8d19c5
@ -6,6 +6,7 @@ use mysqli;
|
|||||||
use mysqli_sql_exception;
|
use mysqli_sql_exception;
|
||||||
use mysqli_stmt;
|
use mysqli_stmt;
|
||||||
use SilverStripe\Core\Config\Config;
|
use SilverStripe\Core\Config\Config;
|
||||||
|
use SilverStripe\Core\Environment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connector for MySQL using the MySQLi method
|
* Connector for MySQL using the MySQLi method
|
||||||
@ -81,15 +82,21 @@ class MySQLiConnector extends DBConnector
|
|||||||
// Connection charset and collation
|
// Connection charset and collation
|
||||||
$connCharset = Config::inst()->get(MySQLDatabase::class, 'connection_charset');
|
$connCharset = Config::inst()->get(MySQLDatabase::class, 'connection_charset');
|
||||||
$connCollation = Config::inst()->get(MySQLDatabase::class, 'connection_collation');
|
$connCollation = Config::inst()->get(MySQLDatabase::class, 'connection_collation');
|
||||||
|
$socket = Environment::getEnv('SS_DATABASE_SOCKET');
|
||||||
|
$flags = Environment::getEnv('SS_DATABASE_FLAGS');
|
||||||
|
|
||||||
|
$flags = $flags ? array_reduce(explode(',', $flags), function ($carry, $item) {
|
||||||
|
$item = trim($item);
|
||||||
|
return $carry | constant($item);
|
||||||
|
}, 0) : $flags;
|
||||||
|
|
||||||
$this->dbConn = mysqli_init();
|
$this->dbConn = mysqli_init();
|
||||||
|
|
||||||
// Use native types (MysqlND only)
|
// Use native types (MysqlND only)
|
||||||
if (defined('MYSQLI_OPT_INT_AND_FLOAT_NATIVE')) {
|
if (defined('MYSQLI_OPT_INT_AND_FLOAT_NATIVE')) {
|
||||||
$this->dbConn->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, true);
|
$this->dbConn->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, true);
|
||||||
|
|
||||||
// The alternative is not ideal, throw a notice-level error
|
|
||||||
} else {
|
} else {
|
||||||
|
// The alternative is not ideal, throw a notice-level error
|
||||||
user_error(
|
user_error(
|
||||||
'mysqlnd PHP library is not available, numeric values will be fetched from the DB as strings',
|
'mysqlnd PHP library is not available, numeric values will be fetched from the DB as strings',
|
||||||
E_USER_NOTICE
|
E_USER_NOTICE
|
||||||
@ -117,7 +124,9 @@ class MySQLiConnector extends DBConnector
|
|||||||
$parameters['username'],
|
$parameters['username'],
|
||||||
$parameters['password'],
|
$parameters['password'],
|
||||||
$selectedDB,
|
$selectedDB,
|
||||||
!empty($parameters['port']) ? $parameters['port'] : ini_get("mysqli.default_port")
|
!empty($parameters['port']) ? $parameters['port'] : ini_get("mysqli.default_port"),
|
||||||
|
$socket ?? null,
|
||||||
|
$flags ?? 0
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($this->dbConn->connect_error) {
|
if ($this->dbConn->connect_error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user