Browse Source

Work around MySQL stupidity

rpm
J. King 3 years ago
parent
commit
5cfa01f4d5
  1. 2
      lib/Db/MySQL/Driver.php
  2. 6
      tests/lib/AbstractTest.php
  3. 5
      tests/lib/DatabaseDrivers/MySQL.php

2
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) {

6
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

5
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;
}

Loading…
Cancel
Save