diff --git a/lib/Db/MySQL/Driver.php b/lib/Db/MySQL/Driver.php index 1c0da1e1..d2c538bc 100644 --- a/lib/Db/MySQL/Driver.php +++ b/lib/Db/MySQL/Driver.php @@ -164,6 +164,8 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver { protected function makeConnection(string $db, string $user, string $password, string $host, int $port, string $socket): void { $this->db = mysqli_init(); + $this->db->options(\MYSQLI_SET_CHARSET_NAME, "utf8mb4"); + $this->db->options(\MYSQLI_OPT_INT_AND_FLOAT_NATIVE, false); $this->db->options(\MYSQLI_OPT_CONNECT_TIMEOUT, ceil(Arsse::$conf->dbTimeoutConnect)); @$this->db->real_connect($host, $user, $password, $db, $port, $socket); if ($this->db->connect_errno) { diff --git a/tests/lib/AbstractTest.php b/tests/lib/AbstractTest.php index 3ed6fc4d..5bfd0353 100644 --- a/tests/lib/AbstractTest.php +++ b/tests/lib/AbstractTest.php @@ -324,11 +324,15 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase { } public function assertResult(array $expected, Result $data): void { + $data = $data->getAll(); // stringify our expectations if necessary if (static::$stringOutput ?? false) { $expected = $this->stringify($expected); + // MySQL is extra-special and mixes strings and integers, so we cast the data, too + if ((static::$implementation ?? "") === "MySQL") { + $data = $this->stringify($data); + } } - $data = $data->getAll(); $this->assertCount(sizeof($expected), $data, "Number of result rows (".sizeof($data).") differs from number of expected rows (".sizeof($expected).")"); if (sizeof($expected)) { // make sure the expectations are consistent diff --git a/tests/lib/DatabaseDrivers/MySQL.php b/tests/lib/DatabaseDrivers/MySQL.php index 01501f15..0df43d3f 100644 --- a/tests/lib/DatabaseDrivers/MySQL.php +++ b/tests/lib/DatabaseDrivers/MySQL.php @@ -21,7 +21,10 @@ trait MySQL { if (!class_exists("mysqli")) { return null; } - $d = @new \mysqli(Arsse::$conf->dbMySQLHost, Arsse::$conf->dbMySQLUser, Arsse::$conf->dbMySQLPass, Arsse::$conf->dbMySQLDb, Arsse::$conf->dbMySQLPort); + $d = mysqli_init(); + $d->options(\MYSQLI_OPT_INT_AND_FLOAT_NATIVE, false); + $d->options(\MYSQLI_SET_CHARSET_NAME, "utf8mb4"); + @$d->real_connect(Arsse::$conf->dbMySQLHost, Arsse::$conf->dbMySQLUser, Arsse::$conf->dbMySQLPass, Arsse::$conf->dbMySQLDb, Arsse::$conf->dbMySQLPort); if ($d->connect_errno) { return null; }