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.
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.
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:
$conn = mysql_connect("localhost", "username", "password"); mysql_select_db("database_name", $conn);
$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.
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.
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
LEAVE A COMMENT
I am an entrepreneur based in Sydney Australia. I was born in Vietnam, grew up in Italy and currently residing in Australia. I started my first business venture Advertise Me from a random idea and have never looked back since. My passion is in the digital space, affiliate marketing, fitness and I launched several digital products. You will find these on the portfolio page.
I’ve decided to change from a Vegetarian to a Vegan diet and started a website called Veggie Meals.
I started this blog so I could leave a digital footprint of my random thoughts, ideas and life in general.
If any of the articles helped you in any way, please donate. Thank you for your help.
Affiliate Compensated: there are some articles with links to products or services that I may receive a commission.