Frequent errors when changing PHP versions

PHP is under constant development, therefore updates and new versions are available at irregular intervals. Sometimes updates cause scripts to stop working and therefore need to be adjusted. A tip in advance: A simple update of your CMS or plugin to a current version often helps.

In this article we want to discuss with you common bugs in PHP version changes and work out solutions to fix them.

Register a domain name

Build your brand on a great domain, including SSL and a personal consultant!

Private registration
24/7 support
Email

Conversion of SQL functions when updating from PHP5 to PHP7

The development of PHP 7 partially abandoned backwards compatibility. You can find more backgrounds in the Migration guides of the PHP project . One of the most common errors that occurs when updating from PHP5 to PHP7 is the change from PHP function mysql() to mysqli().

In concrete terms, the function mysql() no longer works. This function has been replaced by mysqli(). Many functions can be corrected by adding a "i" to the existing mysql() function.

The following error message tells you that you are using a database driver that is no longer supported:

 

Fatal error: Uncaught Error: Call to undefined function mysql_connect() in… line…

Connection Identifier

To switch to the new database version, use the new connection identifier in addition to the mysql(i) functions. In our example this is called: $link

<?php  
// old: mysql() establish connection:
mysql_connect("localhost", "root", "", "test");

// new: mysqli() establish connection:
$link = mysqli_connect("localhost", "root", "", "test");
?>

Reading data from the DB table

Here an example of a simple data query:

 <?php
$link = mysqli_connect("localhost", "root", "", "test");

// Read datarecords (example)
 $datarecords = mysqli_query($link,
 "SELECT `name`, `text`, `date` FROM `news`");

// Read data records
while (list($name, $text, $date) = mysqli_fetch_array($datarecords)) {
 echo "<p>$name - $titel - $text - $date</p>";
}
?>

If you want to know more about our background: The following external article provides an introduction and background to the possibilities available to you in developing a PHP application that needs to interact with a MySQL database. call article


Wait! We’ve got something for you!
Discover our special deals at IONOS!
Our most popular products, including cloud storage, hosting,
domains and more - now on sale.