Jump to content

Upgrading my webpages tot PHP 7.4.2


Recommended Posts

Hello,

5 years ago I created a website with a MySQL database and PHP 5.6 scripting with Dreamweaver CS6.
Now I have to upgrade my pages to PHP 7.4.2 using Dreamweaver 2020 and using mysqli connection.

How do I proceed to change my pages ? Do I have to rescript all my PHP pages or is there an easy way to adapt the pages.

Thank you for helping out a PHP dummy. 

 

 

 

 

 

Link to comment
Share on other sites

If you were using mysql_* functions before then you need to use mysqli_* functions now. They are very similar. Check the documentation because it is not just a matter of adding 'i's to the function names.

Otherwise the easiest way to find out what you need to change is to test the site locally on PHP 7 and see what happens. PHP 5.6 to 7.4 isn't a huge set of changes, but there are a number of differences that aren't necessarily easy to spot.

Also check the migration guides. Each guide between 5.6 and 7.4.

Link to comment
Share on other sites

Depending on the way the app is written you also might be able to get away with a backwards compatability shim.  I don't recommend or endorse this, but in some cases, it might be an acceptable way to avoid having to change all your mysql_ calls to mysqli_ (assuming that is all you are actually going to do, rather than actually updating the SQL statement calls and rewriting your code to utilize parameters).

A "Shim" is a library that retrofits old code in some way so that newer code works, so perhaps this is not technically a shim, depending on how you look at it, but the idea is that you use a library that fills in the missing library calls (mysql_) so your existing code will still work.  This would work best if you at least have your mysql connections created in include files, otherwise you will have to go through changing every script that makes a connection.  If you have to make changes all over the place, you are probably better off consolidating code into includes, and changing to mysqli or PDO as others have suggested.  This is a quick retrofit using a mysql backwards compatibility library.

There are some things you need to do in advance.

  • 1st you must have installed a working version of composer
  • You need PDO installed in your PHP
  • 2nd you need to add a composer.json, assuming you don't have one.

At minimum you would update your project composer.json require section

{
    "require": {
        "mattbit/mysql-compat": "^1.1"
    }
}

Use composer to generate an autoloader for you.  This will be created in the {project}/vendor directory.

Let's suppose you have a script in your project root that gets called.  You would add code similar to this to call the autoloader, and to load the compatibility library.

require __DIR__ . '/vendor/autoload.php';
Mattbit\MysqlCompat\Mysql::defineGlobals();

This will add the shims for the old mysql_ code, and if all goes as planned, your existing code will work unaltered.

Again, I'm not recommending this, but it if's an old site that you have no plans to update, and just want to keep it working as is, this does work, and doesn't require you to go find all your mysql_ calls and change them.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.