TinyMVC: PDO & UTF-8 Character Set

When setting up the initial model for a TinyMVC project, I got the following error:

Message: Can’t connect to PDO database ‘mysql’. Error: SQLSTATE[HY000] [2019] Can’t initialize character set UTF-8 (path: /usr/share/mysql/charsets/)

After looking in /path/to/tinymvc/sysfiles/plugins/tinymvc_pdo.php I noticed the following on line 95:

    if(empty($config['charset']))
        $config['charset'] = 'UTF-8';

Since nothing appeared wrong, I did a quick Google search and found this bit of information:

Just tried your recommendation on the other server with php 5.3.6 and it worked with utf8 versus utf-8. Just to double check i tried it again with utf-8 and that didn’t work

So, armed with that knowledge, I updated /path/to/tinymvc/sysfiles/plugins/tinymvc_pdo.php to read as:


    if(empty($config['charset'])) {
        $config['charset'] = 'UTF8';
    }

Bingo! After saving the file and refreshing, the error was gone!

Nick

MySQL Database Error: Can’t create table … (errno: 121)

I came across this problem this morning when copying a table structure and creating a backup table. The reason I received it was because I had not not also renamed my foreign keys constraints.

Using the fk_<table_name>_key pattern fixed the problem and the table was created without error.

Nick

mysqldump: Got error: 1016: Can’t open file: ‘…’ (errno: 24) when using LOCK TABLES

Stuck? Try the following command:

mysqldump --lock-tables=false -u******** -p {database_name} > {database_name}.sql

Nick

MySQL Data Type INT: Signed vs. Unsigned

I have been meaning to actually look at the storage differences between signed and unsigned for a few months now, and I have finally remembered to do it! A quick Google search returned just the information I was looking for, so I thought that I would repost the blurb that was worthwhile.

An UNSIGNED INT can go from 0 to 4294967295 (aprox 4 billion). A SIGNED INT , on the other hand, starts at -2147483648 and goes to 2147483648 (aprox 2 billion).

source: http://www.verysimple.com/blog/2006/10/22/mysql-data-type-optimization-tips/

Nick

Using ORDER BY with UPDATE

Yep, you read the title correctly. This problem presented itself when I needed a quick and dirty way to update an auto_increment [a_i] field in a database. I wanted to move the a_i field up by n, where a_i > x. The query looked like this:

UPDATE table_name SET id = (id + n) WHERE id > x ORDER BY id DESC

To see why one must do it this way, try to do the query without the ORDER BY.

Nick