2019-01-12 17:43:06 +00:00
|
|
|
<?php
|
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2019-08-25 17:19:11 +00:00
|
|
|
namespace JKingWeb\Arsse\Test\DatabaseDrivers;
|
2019-01-12 17:43:06 +00:00
|
|
|
|
|
|
|
use JKingWeb\Arsse\Arsse;
|
|
|
|
|
|
|
|
trait MySQLPDO {
|
|
|
|
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;
|
|
|
|
protected static $stringOutput = true;
|
2020-03-01 20:16:50 +00:00
|
|
|
|
2019-01-12 17:43:06 +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,
|
2019-01-12 17:43:06 +00:00
|
|
|
];
|
|
|
|
foreach ($params as $k => $v) {
|
|
|
|
$dsn[] = "$k=$v";
|
|
|
|
}
|
|
|
|
$dsn = "mysql:".implode(";", $dsn);
|
2019-01-14 04:17:19 +00:00
|
|
|
$d = new \PDO($dsn, Arsse::$conf->dbMySQLUser, Arsse::$conf->dbMySQLPass, [
|
2020-03-01 20:16:50 +00:00
|
|
|
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
|
2019-01-14 04:17:19 +00:00
|
|
|
\PDO::MYSQL_ATTR_MULTI_STATEMENTS => false,
|
|
|
|
]);
|
|
|
|
foreach (\JKingWeb\Arsse\Db\MySQL\PDODriver::makeSetupQueries() as $q) {
|
|
|
|
$d->exec($q);
|
|
|
|
}
|
|
|
|
return $d;
|
2019-01-12 17:43:06 +00:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-03-01 20:16:50 +00:00
|
|
|
|
2019-01-12 17:43:06 +00:00
|
|
|
public static function dbTableList($db): array {
|
|
|
|
return MySQL::dbTableList($db);
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:34:03 +00:00
|
|
|
public static function dbTruncate($db, array $afterStatements = []): void {
|
2019-01-12 17:43:06 +00:00
|
|
|
MySQL::dbTruncate($db, $afterStatements);
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:34:03 +00:00
|
|
|
public static function dbRaze($db, array $afterStatements = []): void {
|
2019-01-12 17:43:06 +00:00
|
|
|
MySQL::dbRaze($db, $afterStatements);
|
|
|
|
}
|
|
|
|
}
|