Skip to content

Commit c6fd28f

Browse files
committed
remove config charset, add config init string or array
1 parent d8695b7 commit c6fd28f

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

lib/MysqliManager/.mysqli_manager.ini.dist

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
; This is a sample configuration file
2+
; Comments start with ';', as in php.ini
3+
14
[default]
25
host="localhost"
36
port="3306"
@@ -6,7 +9,8 @@ password="pass"
69
socket=""
710
dbname="testdb"
811
persistent="true"
9-
charset="utf8"
12+
; init should be array or string
13+
init = SET NAMES 'utf8mb4' COLLATE 'utf8mb4_unicode_ci'
1014

1115
[secondary]
1216
host="localhost"
@@ -17,6 +21,7 @@ socket=""
1721
dbname="testdb"
1822
persistent="true"
1923
charset="utf8"
24+
init[] = SET NAMES 'utf8mb4' COLLATE 'utf8mb4_unicode_ci'
2025

2126
[other]
2227
host="localhost"
@@ -27,4 +32,4 @@ socket=""
2732
dbname="testdb"
2833
persistent="true"
2934
charset="utf8"
30-
35+
init[] = SET NAMES 'utf8mb4' COLLATE 'utf8mb4_unicode_ci'

lib/MysqliManager/Connection.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ public function __construct(MysqliManager $manager, $name = MysqliManager::DEFAU
3434
$config->socket = $configuration['socket'] ?? null;
3535
$config->dbname = $configuration['dbname'] ?? null;
3636
$config->persistent = $configuration['persistent'] ?? true;
37-
$config->charset = $configuration['charset'] ?? $manager::DEFAULT_CHARSET;
37+
$config->init = $configuration['init'] ?? [];
38+
if (is_scalar($config->init)) {
39+
$config->init = [$config['init']];
40+
}
3841
$hash = spl_object_hash($this);
3942
$driver = new mysqli_driver();
4043
$driver->report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT;
@@ -59,7 +62,9 @@ public function __construct(MysqliManager $manager, $name = MysqliManager::DEFAU
5962
$config->port
6063
);
6164
}
62-
$this->set_charset($config->charset);
65+
foreach ($config['init'] as $sql) {
66+
$this->query($sql);
67+
}
6368
$this->select_db($config->dbname);
6469
}
6570

lib/MysqliManager/MysqliManager.php

-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ class MysqliManager
2525
*/
2626
const DEFAULT_PORT = '3306';
2727

28-
/**
29-
* @var string
30-
*/
31-
const DEFAULT_CHARSET = 'utf8';
32-
3328
/**
3429
* @var string
3530
*/

0 commit comments

Comments
 (0)