I recently installed a CodeIgniter 3.x application and another PHP application on a new server, I did run into some issues immediately, the apps were broken, it connected to the database. Did not allow me to insert new data, gave me an error, took me some time to figure it out, the issue was that MySQL on the new server was set to strict mode.
MySQL has had a strict mode since 5.1, but in 5.7 it became the default.
For the CodeIgniter 3.x App, I fixed the issue in the code: edit your
config file, and set the key
with a value of
For my other PHP application, I did not have that choice. One option that I could do was to add into my code after selecting the database
the following code
mysql_query("SET SESSION sql_mode = ''");
This will remove the strict mode only when you execute the specific PHP script, you would need to add it in all places that you do mysql_connect.
Another way to disable strict mode globally on your server (maybe some variations between different servers) are as follows:
Your configuration file MySQL actually looks at five different places for configuration files, so you can make the change in several places. It’ll look in
is user-specific, and the third and fourth options rely on specifics from your environment.
On a default server, MySQL configuration will live in
so let’s put our changes there. SSH into your server and use Vim to edit that file.
Open the file my.cnf and scroll down the file a bit, you’ll find the [mysqld] section. We’re going to add a new key, sql_mode. On MySQL 5.7, the default values for this key out of the box are:
The strict mode comes from STRICT_TRANS_TABLES. So, let’s overwrite the sql_mode and set it to be the same as the default, but without strict mode.
Save the file, and restart MySQL. From the command line that would be
sudo /etc/init.d/mysql restart