Few days ago, I came across many migration problems when I have to migrate my client’s PHP website from PHP 4.X.X to the PHP 5.6.17. So, I want to share my problems and solutions with you guys.

  1. The deprecated functions: This on is just easy enough to use “find and replace” function which exists in most of the editor.

As I migrated from PHP 4.X.X to PHP 5.6.17 I found several functions need to be changed as follows:

all “mysql_” functions must be replaced with “mysqli_” functions.

There are a few cautions you need to take a look here!

  • when you change from mysql_fetch_array to mysqli_fetch_array you should specify the result type in the section parameter. the possible values are MYSQLI_ASSOC, MYSQLI_NUM or MYSQLI_BOTH.
  • mysql_db_query($dbname, $sql) must be replaced with mysqli_query($connection, $sql). As you can see, not only i is added to the function name but the first parameter is changed from database name to database connection.

2. You cannot use “<?” (without php) anymore. All of them must be replaced with “<?php. if you find any part of the broken code in the browser, this must be the case.

3. You will find Notice: Undefined variable and Notice: Undefined index

There are 2 solutions for this:

  • Check for NULL value before you use array values. The Change the code
    From : $variable=$array_name[index]
    To : $variable=array_key_exists(‘index’,$array_name) ? $array_name[‘index’] : null;


  • Change the configuration in “php.ini”
    From : error_reporting = E_ALL
    To : error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT

4. SQL warning Field doesn’t have a default values

Change “sql-mode” configuration in my.ini :

Hope those problem and solution help someone who come across the same problems as me. Cheers!