diff --git a/DataStorage/Database/Connection/MysqlConnection.php b/DataStorage/Database/Connection/MysqlConnection.php index 5c1b856c9..c1d994b07 100644 --- a/DataStorage/Database/Connection/MysqlConnection.php +++ b/DataStorage/Database/Connection/MysqlConnection.php @@ -69,7 +69,7 @@ final class MysqlConnection extends ConnectionAbstract $this->prefix = $dbdata['prefix'] ?? ''; try { - $this->con = new \PDO($this->dbdata['db'] . ':host=' . $this->dbdata['host'] . ':' . $this->dbdata['port'] . ';dbname=' . $this->dbdata['database'] . ';charset=utf8', $this->dbdata['login'], $this->dbdata['password']); + $this->con = new \PDO($this->dbdata['db'] . ':host=' . $this->dbdata['host'] . ':' . $this->dbdata['port'] . ';dbname=' . $this->dbdata['database'] . ';charset=utf8mb4', $this->dbdata['login'], $this->dbdata['password']); $this->con->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false); $this->con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); diff --git a/DataStorage/Database/Schema/Grammar/MysqlGrammar.php b/DataStorage/Database/Schema/Grammar/MysqlGrammar.php index 80fb9829e..640829331 100644 --- a/DataStorage/Database/Schema/Grammar/MysqlGrammar.php +++ b/DataStorage/Database/Schema/Grammar/MysqlGrammar.php @@ -136,6 +136,6 @@ class MysqlGrammar extends Grammar */ protected function compileCreateTableSettings(BuilderAbstract $query, bool $settings) : string { - return 'ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1'; + return 'ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1'; } } diff --git a/tests/DataStorage/Database/DataMapperAbstractTest.php b/tests/DataStorage/Database/DataMapperAbstractTest.php index ec94d705d..d3df8b55a 100644 --- a/tests/DataStorage/Database/DataMapperAbstractTest.php +++ b/tests/DataStorage/Database/DataMapperAbstractTest.php @@ -91,7 +91,7 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase `test_base_datetime` datetime DEFAULT NULL, `test_base_datetime_null` datetime DEFAULT NULL, /* There was a bug where it returned the current date because new \DateTime(null) === current date which is wrong, we want null as value! */ PRIMARY KEY (`test_base_id`) - )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;' )->execute(); $GLOBALS['dbpool']->get()->con->prepare( @@ -99,7 +99,7 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase `test_belongs_to_one_id` int(11) NOT NULL AUTO_INCREMENT, `test_belongs_to_one_string` varchar(254) NOT NULL, PRIMARY KEY (`test_belongs_to_one_id`) - )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;' )->execute(); $GLOBALS['dbpool']->get()->con->prepare( @@ -107,7 +107,7 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase `test_owns_one_id` int(11) NOT NULL AUTO_INCREMENT, `test_owns_one_string` varchar(254) NOT NULL, PRIMARY KEY (`test_owns_one_id`) - )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;' )->execute(); $GLOBALS['dbpool']->get()->con->prepare( @@ -116,7 +116,7 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase `test_has_many_direct_string` varchar(254) NOT NULL, `test_has_many_direct_to` int(11) NOT NULL, PRIMARY KEY (`test_has_many_direct_id`) - )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;' )->execute(); $GLOBALS['dbpool']->get()->con->prepare( @@ -124,7 +124,7 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase `test_has_many_rel_id` int(11) NOT NULL AUTO_INCREMENT, `test_has_many_rel_string` varchar(254) NOT NULL, PRIMARY KEY (`test_has_many_rel_id`) - )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;' )->execute(); $GLOBALS['dbpool']->get()->con->prepare( @@ -133,7 +133,7 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase `test_has_many_rel_relations_src` int(11) NOT NULL, `test_has_many_rel_relations_dest` int(11) NOT NULL, PRIMARY KEY (`test_has_many_rel_relations_id`) - )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;' )->execute(); } diff --git a/tests/DataStorage/Database/Query/BuilderTest.php b/tests/DataStorage/Database/Query/BuilderTest.php index add1e872e..f735e2ea3 100644 --- a/tests/DataStorage/Database/Query/BuilderTest.php +++ b/tests/DataStorage/Database/Query/BuilderTest.php @@ -22,7 +22,7 @@ use phpOMS\DataStorage\Database\Query\Builder; */ class BuilderTest extends \PHPUnit\Framework\TestCase { - protected $con = null; + protected $con; protected function setUp() : void { diff --git a/tests/DataStorage/Database/Schema/BuilderTest.php b/tests/DataStorage/Database/Schema/BuilderTest.php index ec5cab34e..e83c8ea80 100644 --- a/tests/DataStorage/Database/Schema/BuilderTest.php +++ b/tests/DataStorage/Database/Schema/BuilderTest.php @@ -53,7 +53,7 @@ class BuilderTest extends \PHPUnit\Framework\TestCase public function testMysqlCreateTable() : void { $query = new Builder($this->con); - $sql = 'CREATE TABLE `user_roles` (`user_id` INT NOT NULL AUTO_INCREMENT, `role_id` VARCHAR(10) DEFAULT \'1\' NULL, PRIMARY KEY (`user_id`), FOREIGN KEY (`user_id`) REFERENCES `users` (`ext1_id`), FOREIGN KEY (`role_id`) REFERENCES `roles` (`ext2_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'; + $sql = 'CREATE TABLE `user_roles` (`user_id` INT NOT NULL AUTO_INCREMENT, `role_id` VARCHAR(10) DEFAULT \'1\' NULL, PRIMARY KEY (`user_id`), FOREIGN KEY (`user_id`) REFERENCES `users` (`ext1_id`), FOREIGN KEY (`role_id`) REFERENCES `roles` (`ext2_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;'; self::assertEquals( $sql, $query->createTable('user_roles')