eee
This commit is contained in:
+19
-10
@@ -14,6 +14,7 @@ namespace Database;
|
||||
use Database\Affair\BeginTransaction;
|
||||
use Database\Affair\Commit;
|
||||
use Database\Affair\Rollback;
|
||||
use Database\Base\Driver;
|
||||
use Database\Base\PDO;
|
||||
use Exception;
|
||||
use Kiri\Abstracts\Component;
|
||||
@@ -45,6 +46,7 @@ class Connection extends Component
|
||||
public string $charset = 'utf-8';
|
||||
public string $tablePrefix = '';
|
||||
public string $database = '';
|
||||
public string $driver = 'mysql';
|
||||
public int $timeout = 30;
|
||||
public int $waite_time = 3;
|
||||
public int $tick_time = 60000;
|
||||
@@ -154,7 +156,7 @@ class Connection extends Component
|
||||
*/
|
||||
private function getName(): string
|
||||
{
|
||||
return 'mysql.' . $this->cds;
|
||||
return strtolower($this->driver) . '.' . $this->cds;
|
||||
}
|
||||
|
||||
|
||||
@@ -355,15 +357,22 @@ class Connection extends Component
|
||||
*/
|
||||
public function newConnect(): \PDO
|
||||
{
|
||||
$pdo = new PDO($this->database, $this->cds, $this->username, $this->password, [
|
||||
\PDO::ATTR_CASE => \PDO::CASE_NATURAL,
|
||||
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
|
||||
\PDO::ATTR_ORACLE_NULLS => \PDO::NULL_NATURAL,
|
||||
\PDO::ATTR_STRINGIFY_FETCHES => false,
|
||||
\PDO::ATTR_EMULATE_PREPARES => true,
|
||||
\PDO::ATTR_TIMEOUT => $this->timeout,
|
||||
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $this->charset
|
||||
]);
|
||||
$driver = strtolower($this->driver);
|
||||
$options = [
|
||||
\PDO::ATTR_CASE => \PDO::CASE_NATURAL,
|
||||
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
|
||||
\PDO::ATTR_ORACLE_NULLS => \PDO::NULL_NATURAL,
|
||||
\PDO::ATTR_STRINGIFY_FETCHES => false,
|
||||
\PDO::ATTR_EMULATE_PREPARES => true,
|
||||
\PDO::ATTR_TIMEOUT => $this->timeout,
|
||||
];
|
||||
|
||||
// MySQL 特定的选项
|
||||
if ($driver === 'mysql') {
|
||||
$options[\PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES ' . $this->charset;
|
||||
}
|
||||
|
||||
$pdo = new PDO($this->database, $this->cds, $this->username, $this->password, $options, $driver);
|
||||
foreach ($this->attributes as $key => $attribute) {
|
||||
$pdo->setAttribute($key, $attribute);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user