Frequent errors when changing PHP versions

The text on this page was translated by translation software. A revised version from our editors will be available soon.

Leave your reply

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.

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

Frequent errors of our customers and the corresponding solution

We want to make the exchange possible with this article.

Share with us your personal bugs that occurred when changing the PHP version!

You have already solved this error? Great! Share your solution with us and the community readers!

We are happy about every contribution...

This article was published on 26 Feb 2019 by sebastian.zientek as part of the topic PHP .