Php 5.6 to php7


hi guys, I wonder if you can help. I signed up to fasthost a few months ago and the package was php7. i want to build an e commerce website and i have been looking for an e commerce course in php7 but everywhere i looked was php 5.6.

the course that i found it had everything i wanted and looked very interesting to do. it is this one

i would like to know after doing a course like this in php 5.6 how easy or hard it would be to upgrade the website to php7? would the whole code have to be written again and how long is it until they make php5.6 obsolete?

many thanks guys


I don’t see any code. We need to see the code to give you an answer.


Active support for php5.6 has already ended, with security support ending this year. See the following link -

You can find the major changes in each php version in the migration appendixes in documentation.

The php5.6 to php7+ changes that will affect most common code are the removal of the mysql and ereg extensions. If the php coding you are learning is using the php PDO extension, this won’t be affected by a change to php7+.


thanks for your reply benanamen. what it is i was having trouble connecting to fastehosts database. i spoke to them in live chat and they said i needed to downgrade to php5.6 but i thought surely i could connect to the database whether it was php 5.6 or php7. i tried everything from even using the servers ip address but it still wouldnt connect.

this is my code
this is bodyleft.php

    <div id="bodyleft"><h3>Content Mangerment System</h3>
        	<li><a href="index.php">Home</a></li>
            <h3>Category Management</h3>
            <li><a href="index.php?viewall_cat">Viewall Categories</a></li>
            <li><a href="index.php?viewall_sub_cat">Viewall Sub Categories</a></li>
            <h3>Product Management</h3>
            <li><a href="index.php?add_products">Add New Products</a></li>
            <li><a href="index.php?viewall_products">View All Products</a></li>
            <li><a href="index.php?dis_pro">View All Discount Products</a></li>
            <li><a href="index.php?wish">View All WishList Products</a></li>
            <li><a href="index.php?out_stock">View All Out Of Stock Products</a></li>
        	<h3>Order Management</h3>
            <li><a href="index.php?complete_order">View All Complete Orders</a></li>
        	<li><a href="index.php?pending_order">View All Pending Orders</a></li>
        	<li><a href="index.php?cancle_order">View All Cancle Orders</a></li>
            <h3>Other Management</h3>
            <li><a href="index.php?customer">View All Customers</a></li>
            <li><a href="index.php?country">View All Country</a></li>
            <li><a href="index.php?state">View All State</a></li>
            <li><a href="index.php?slider">Edit Image Slider</a></li>


this is cat.php
    <div id="bodyright">
    	<h3>View All Categories</h3>
        <form id='scroll' method="post" enctype="multipart/form-data">
        	<table cellspacing="0">
                	<td>Enter Category Name :</td>
                    <td><input type="text" name="cat_name" /></td>
            <center><button name="add_cat">Add Category</button></center>
    <?php include("inc/db.php");
    $add_cat=$con->prepare("insert into main_cat(cat_name)values('$cat_name')");
this is bodyright.php
    	if(!isset($_GET['viewall_cat'])){ ?>
    <div id="bodyright"></div>
    <?php }?>

this is db.php

    	$con=new PDO("mysqli:host=dbname=bargaincentre1_store","root","password");


Is this the code that was shown to you in the tutorial?


yes it is, sorry i dont know how to show it in blocks of code, some of the code isnt showing and coming through as links


three backticks ```

So, if the tutorial is showing you to do PDO like that, the information they are using is poor at best and definitely not what you want to be following. They are using prepared statements, without preparing them.


there is 101 tutorials and i am only on the 9th one. on the 9th tutorial they are just connecting to the database. there is still alot to do. but surely i can connect to the database never mind if it is in php 5.6 or php7 through the connection file. it just wont connect the the database.


The php code in this tutorial is bad. Do not use it.


thank you phdr for your reply. like i said there is 101 tutorials and it looks very indeapth. have you see the course before?


Or there is a book I would recommend.


thanks for your reply. the second one you posted " E Commerce Website Development In PHP With PDO " is the course it is. do you know anyone that has done that course?


:man_facepalming: I should have looked through the course more thoroughly. My first red flag was it saying to use Dreamweaver as the IDE. I’ll edit the post to remove that, that is a hack making money from people thinking he knows what he’s doing…

This is the book I would push in place of that awful course.


thanks for your reply astonecipher. so what you are saying is the fella has made 101 tutorials of rubish and i should get my money back then? what a disappointment the course looked great. thanks for everyones reply it has been most helpful.


Skip to the last 10 tutorials, do they include the final code? Look at the final code. If it’s still using bad code at number #99 then you know for sure these tutorials are not worth your time.


Hi thinsoldier, thank you for your reply. it does include the final code. To be truthful with you i dont really know what good and bad code looks like as i am a beginner at this. what i think i will do is do the first 20-30 tutorials, show the code on here and see how rubbish his coding actually is. May be there is a method in my madness in which before i can see what i should not be doing then i learn the right way to code


Like was said earlier, if they are still using prepared statements, without preparing them in the final version of the code I’d skip these tutorials.

You could learn the general skills necessary to build any app from a better tutorial and then refer back to the e-commerce specific aspects of this tutorial if they happen to go into great details about what they’re doing and why.

I would also personally avoid 90% of the headache and risk of human error of dealing with PDO directly and use an ORM/query builder/active record class wherever possible. Save manual PDO usage for the few complex queries that would be difficult or slow with an ORM.

You can use the Laravel Framework’s Eloquent ORM in any project independently of the rest of Laravel. There are others both more complex and less complex than Eloquent. I’m a fan of for beginners.


You should be learning, developing, and debugging code/query(ies) on a localhost development system and only put it onto a live/public server once you have a complete and secure application.

However, there’s nothing in the posted code that is php7+ specific or that would prevent a database connection using the PDO extension from working.

If you weren’t able to connect to the database server, the problem is in the connection values you are using, and you should have been getting an uncaught php exception that would contain information that would help pin down the problem. If there was no connection related error displayed or logged, you need to set php’s error_reporting to E_ALL and either set display_errors to ON or set log_errors to ON.

For fasthosts, it appears that the host value should be the database server’s ip address (if you used your web site’s ip address, that is not correct.) The database name is whatever you picked when you created the database. The username and password should be whatever you picked when you created the database user and you shouldn’t have been able to pick ‘root’ as the username and if you were able to, pick some other less common and more unique username.

The database connection code needs to also -

  1. Set the character set to match the character set being used by your database tables (UTF8 in a common/good choice.)
  2. Set emulated prepared queries to false.
  3. Set the error mode to exceptions, so that all the rest of the PDO database statements will throw exceptions.
  4. Set the default fetch mode to assoc, so that you don’t have to specify a fetch mode in most statements.

Here is an example of typical PDO connection code -

// fill in your connection values -
$DB_HOST = ''; // db hostname or ip address
$DB_USER = ''; // db username
$DB_PASS = ''; // db password
$DB_NAME = ''; // db name
$DB_ENCODING = 'utf8'; // db character encoding

$pdo = new pdo("mysql:host=$DB_HOST;dbname=$DB_NAME;charset=$DB_ENCODING",$DB_USER,$DB_PASS);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // set the error mode to exceptions
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES,false); // run real prepared queries
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_ASSOC); // set default fetch mode to assoc

Here’s specifically what the code is doing incorrectly for the prepared query - it’s putting external/unknown data directly into the sql query statement (which is how sql injection is accomplished) via a php variable, then has php statements like it is using an actual prepared query, which will function and query for and retrieve the data, but is not secure. The code should instead be showing you how to put a ? place-holder in the sql query statement where the data goes, then supply the data when the query gets executed (the simplest method of which is to supply an array of data in the execute() method call.)

The code is also having the programmer (you) manually write out navigation links (a correct content management system would dynamically produce navigation) and is creating unnecessary variables by copying variables to other variables without a good reason.