// get configuration
$dbHost = $dbUser = $dbPassword = $dbName = '';
$dbPort = 0;
+ $defaultDriverOptions = [];
require(WCF_DIR.'config.inc.php');
// create database connection
- self::$dbObj = new MySQLDatabase($dbHost, $dbUser, $dbPassword, $dbName, $dbPort);
+ self::$dbObj = new MySQLDatabase($dbHost, $dbUser, $dbPassword, $dbName, $dbPort, false, false, $defaultDriverOptions);
}
/**
*/
protected $tryToCreateDatabase = false;
+ /**
+ * default driver options passed to the PDO constructor
+ * @var array
+ */
+ protected $defaultDriverOptions = [];
+
/**
* Creates a Database Object.
*
* @param string $database SQL database server database name
* @param integer $port SQL database server port
* @param boolean $failsafeTest
- * @param boolean $tryToCreateDatabase
+ * @param boolean $tryToCreateDatabase
+ * @param array $defaultDriverOptions
*/
- public function __construct($host, $user, $password, $database, $port, $failsafeTest = false, $tryToCreateDatabase = false) {
+ public function __construct($host, $user, $password, $database, $port, $failsafeTest = false, $tryToCreateDatabase = false, $defaultDriverOptions = []) {
$this->host = $host;
$this->port = $port;
$this->user = $user;
$this->database = $database;
$this->failsafeTest = $failsafeTest;
$this->tryToCreateDatabase = $tryToCreateDatabase;
+ $this->defaultDriverOptions = $defaultDriverOptions;
if (defined('ENABLE_DEBUG_MODE') && ENABLE_DEBUG_MODE) {
$this->preparedStatementClassName = DebugPreparedStatement::class;
if (!$this->port) $this->port = 3306; // mysql default port
try {
- $driverOptions = [
- \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'"
- ];
+ $driverOptions = $this->defaultDriverOptions;
+ $driverOptions[\PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES 'utf8mb4'";
if (!$this->failsafeTest) {
- $driverOptions = [
- \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4', SESSION sql_mode = 'ANSI,ONLY_FULL_GROUP_BY,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'"
- ];
+ $driverOptions[\PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES 'utf8mb4', SESSION sql_mode = 'ANSI,ONLY_FULL_GROUP_BY,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'";
}
// disable prepared statement emulation since MySQL 5.1.17 is the minimum required version