Change encoding to real utf8

This commit is contained in:
Dennis Eichhorn 2019-10-05 19:59:53 +02:00
parent ac0503c6e9
commit 0f11df6f95
5 changed files with 10 additions and 10 deletions

View File

@ -69,7 +69,7 @@ final class MysqlConnection extends ConnectionAbstract
$this->prefix = $dbdata['prefix'] ?? ''; $this->prefix = $dbdata['prefix'] ?? '';
try { 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_EMULATE_PREPARES, false);
$this->con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $this->con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

View File

@ -136,6 +136,6 @@ class MysqlGrammar extends Grammar
*/ */
protected function compileCreateTableSettings(BuilderAbstract $query, bool $settings) : string 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';
} }
} }

View File

@ -91,7 +91,7 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase
`test_base_datetime` datetime DEFAULT NULL, `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! */ `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`) PRIMARY KEY (`test_base_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' )ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;'
)->execute(); )->execute();
$GLOBALS['dbpool']->get()->con->prepare( $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_id` int(11) NOT NULL AUTO_INCREMENT,
`test_belongs_to_one_string` varchar(254) NOT NULL, `test_belongs_to_one_string` varchar(254) NOT NULL,
PRIMARY KEY (`test_belongs_to_one_id`) PRIMARY KEY (`test_belongs_to_one_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' )ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;'
)->execute(); )->execute();
$GLOBALS['dbpool']->get()->con->prepare( $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_id` int(11) NOT NULL AUTO_INCREMENT,
`test_owns_one_string` varchar(254) NOT NULL, `test_owns_one_string` varchar(254) NOT NULL,
PRIMARY KEY (`test_owns_one_id`) PRIMARY KEY (`test_owns_one_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' )ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;'
)->execute(); )->execute();
$GLOBALS['dbpool']->get()->con->prepare( $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_string` varchar(254) NOT NULL,
`test_has_many_direct_to` int(11) NOT NULL, `test_has_many_direct_to` int(11) NOT NULL,
PRIMARY KEY (`test_has_many_direct_id`) PRIMARY KEY (`test_has_many_direct_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' )ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;'
)->execute(); )->execute();
$GLOBALS['dbpool']->get()->con->prepare( $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_id` int(11) NOT NULL AUTO_INCREMENT,
`test_has_many_rel_string` varchar(254) NOT NULL, `test_has_many_rel_string` varchar(254) NOT NULL,
PRIMARY KEY (`test_has_many_rel_id`) PRIMARY KEY (`test_has_many_rel_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' )ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;'
)->execute(); )->execute();
$GLOBALS['dbpool']->get()->con->prepare( $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_src` int(11) NOT NULL,
`test_has_many_rel_relations_dest` int(11) NOT NULL, `test_has_many_rel_relations_dest` int(11) NOT NULL,
PRIMARY KEY (`test_has_many_rel_relations_id`) 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(); )->execute();
} }

View File

@ -22,7 +22,7 @@ use phpOMS\DataStorage\Database\Query\Builder;
*/ */
class BuilderTest extends \PHPUnit\Framework\TestCase class BuilderTest extends \PHPUnit\Framework\TestCase
{ {
protected $con = null; protected $con;
protected function setUp() : void protected function setUp() : void
{ {

View File

@ -53,7 +53,7 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
public function testMysqlCreateTable() : void public function testMysqlCreateTable() : void
{ {
$query = new Builder($this->con); $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( self::assertEquals(
$sql, $sql,
$query->createTable('user_roles') $query->createTable('user_roles')