Today, I had to do some code debugging and fixed an issue with migrating an old web app for our company Advertise Me. Advertise Me originally focused on digital signage but we’ve grown the business and built several different digital web applications and you can find these listed here: Digital Solutions Software. There was one particular web application that was built on PHP version 5 and since we are migrating to Amazon AWS, we also wanted to upgrade the code to make it compatible with PHP version 7. Yes, we know that version 8 has been released but we decided it wasn’t necessary to upgrade to the latest version.

Just to make it clear, I’m not a developer and in this article, I am sharing how I fixed the issue based on my limited knowledge and experience with coding in PHP. I did some basic troubleshooting and made the web app work on PHP 7 and these points may also help you.

UPGRADING WEB APP FROM PHP 5 TO PHP 7 coding sample

DISPLAY ERRORS

You can either check the log on your server for the errors or you can add the following code to your PHP pages to display them on the browser web page:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

This will display the errors on the pages you’re loading and it will help you figure out what the issue could be.

MYSQL STATEMENTS

After enabling the error display, I was able to see that some of the errors were related to MySQL statements. This was the error:

Got error
 'PHP message: PHP Fatal error:  Uncaught Error: Call to undefined function mysql_connect() in config.php

The SQL statements used in the config file were not compatible with PHP version 7. In particular, the config file needs to have the SQL syntax updated. Here were the changes required:

Before

$conn = mysql_connect("localhost", "username", "password");
mysql_select_db("database_name", $conn);

After

$mysqli = new mysqli("localhost", "username", "password", "database_name");
$mysqli->select_db("database_name");

Once this was fixed, the login page displayed, however when I tried to log in to the system, the following error was generated:

 Got error
 'PHP message: PHP Fatal error:  Uncaught Error: Call to undefined function mysql_query() 

Basically, all the MySQL functions no longer work when using mysql_xxx.

BEFORE

mysql_query()

AFTER

$mysqli->query($query)

This fixed that problem however, there are also other issues relating to old MySQL statements that were not compatible. In order to fix these, I just replaced every instance of the syntax mysql with mysqli.

I was surprised there was no other PHP code that I needed to change besides the above SQL statements.

I hope this helped you in some way and happy coding.

Subscribe to my newsletter where I will share my journey in affiliate marketing, business, technology, fitness and life in general. Hopefully, this motivates you to also change your journey in life.

This field is required.

Subscribe to my newsletter where I will share my journey in affiliate marketing, business, technology, fitness and life in general. Hopefully, this motivates you to also change your journey in life.

This field is required.

If this article helped you in any way and you want to show your appreciation, I am more than happy to receive donations through PayPal. This will help me maintain and improve this website so I can help more people out there. Thank you for your help.

HELP OTHERS AND SHARE THIS ARTICLE


804Shares

LEAVE A COMMENT