PHP is under constant de­vel­op­ment, 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.

Your very own .uk domain name!
Short, sharp, .uk

Looking for an al­tern­at­ive to the tra­di­tion­al .co.uk extension, or want to grow your online presence? Give .uk a try today.

£1 for 1 year!

Con­ver­sion of SQL functions when updating from PHP5 to PHP7

The de­vel­op­ment of PHP 7 partially abandoned backwards com­pat­ib­il­ity. You can find more back­grounds 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…

Con­nec­tion Iden­ti­fi­er

To switch to the new database version, use the new con­nec­tion iden­ti­fi­er 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 back­ground: The following external article provides an in­tro­duc­tion and back­ground to the pos­sib­il­it­ies available to you in de­vel­op­ing a PHP ap­plic­a­tion that needs to interact with a MySQL database. call article

Go to Main Menu