Upgrade PHP5 to PHP7

Spread the love

I have older server to upgrade to PHP7.

PHP7 has better performance and cleaner library.
But some of functions are depricated like ereg_replace, ereg and also mysql is not supported anymore. Instead, preg_replace, preg_match and mysqli are available.

So some of php programming may not work and need to be updated.

To upgrade, use below commands:

sudo add-apt-repository ppa:ondrej/php
sudo apt-get install php7.0 libapache2-mod-php7.0
sudo a2dismod php5
sudo a2enmod php7.0
sudo apachectl restart

It’s quite simple, but I had to change those depricated functions.
Especially mysqli’s usage is slightly different than mysql.

To connect db:

$this->lid = mysqli_connect(DB_HOST,DB_USER,DB_PWD,DB_NAME);

Select DB:

mysqli_select_db($this->lid,DB_NAME)

Query:

$this->qid = mysqli_query($this->lid, $q);

Fetch Array:

$this->record = mysqli_fetch_array($this->qid);

Upgrading to PHP7 wasn’t night mare, it was quite simple and easy.

Facebook Comments

Published by

Titus Choi

I love technology. Working for information technology. Interested in AVR technology. Playing with RC stuff.