1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-24 01:22:41 +00:00
Arsse/tests/lib/DatabaseDrivers/MySQLPDO.php

49 lines
1.6 KiB
PHP
Raw Normal View History

<?php
/** @license MIT
* Copyright 2017 J. King, Dustin Wilson et al.
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
2021-04-14 15:17:01 +00:00
namespace JKingWeb\Arsse\Test\DatabaseDrivers;
use JKingWeb\Arsse\Arsse;
trait MySQLPDO {
2022-01-11 22:54:02 +00:00
use MySQLCommon;
protected static $implementation = "PDO MySQL";
protected static $backend = "MySQL";
protected static $dbResultClass = \JKingWeb\Arsse\Db\PDOResult::class;
protected static $dbStatementClass = \JKingWeb\Arsse\Db\MySQL\PDOStatement::class;
protected static $dbDriverClass = \JKingWeb\Arsse\Db\MySQL\PDODriver::class;
2022-06-05 03:02:24 +00:00
protected static $stringOutput = false;
2020-03-01 20:16:50 +00:00
public static function dbInterface() {
try {
$dsn = [];
$params = [
'charset' => "utf8mb4",
2020-03-01 20:16:50 +00:00
'host' => Arsse::$conf->dbMySQLHost,
'port' => Arsse::$conf->dbMySQLPort,
'dbname' => Arsse::$conf->dbMySQLDb,
];
foreach ($params as $k => $v) {
$dsn[] = "$k=$v";
}
$dsn = "mysql:".implode(";", $dsn);
$d = new \PDO($dsn, Arsse::$conf->dbMySQLUser, Arsse::$conf->dbMySQLPass, [
2020-03-01 20:16:50 +00:00
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
2022-06-05 03:02:24 +00:00
\PDO::ATTR_STRINGIFY_FETCHES => false,
\PDO::MYSQL_ATTR_MULTI_STATEMENTS => false,
]);
foreach (\JKingWeb\Arsse\Db\MySQL\PDODriver::makeSetupQueries() as $q) {
$d->exec($q);
}
return $d;
} catch (\Throwable $e) {
return;
}
}
}