SQL_MODEsetting of my lcoal MySQL database.
By default, I have a fairly restrictive
SQL_MODEfor my local database server, which is set up by this line in my
Now, a lot of people don't know you can
SQL_MODEon a per-session basis. (A lot of people also don't know
SQL_MODEis available as of MySQL 4.1, but that's another story).
Anyway, I just fixed problem. It really was very, very easy:
- Find out which php script actually connects to MySQL
roland@roland-laptop:/var/www/wordpress$ grep -Rn mysql_connect *
wp-includes/wp-db.php:52: $this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword);
wp-includes/wp-db.phpto edit it
roland@roland-laptop:/var/www/wordpress$ kedit wp-includes/wp-db.php
- Locate the
mysql_connectline, and after the wordpress code that checks whether the connection succeeds, add just one line of code:
// fix sql_mode
mysql_query("SET SESSION SQL_MODE := ''",$this->dbh);
// end fix sql_mode
So, basically, I reset the
SQL_MODEto the default for only this session, and let Wordpress do its thing. Well, that seems to help...at least I can install now ;)
Of course, I just reverted from a rather restrictive setting for the
SQL_MODEto an extremely permissive one. But you can do it the other way around too of course!
For example, if your ISP only provides a vanilla MySQL 4.1 or up, you might find MySQL too permissive in accepting invalid dates, or you might not like the way MySQL handles the
Well, it's easy to setup a generic include script to connect to MySQL, just like Wordpress does, and then including a
SET SESSION SQL_MODEstatement, just like I did. Obviously, in that case you would assign a comma-separated list of
SQL_MODEs to it to make MySQL more restrictive. Look here for a full list of SQL_Modes.