Yann63 Posted July 10, 2020 Share Posted July 10, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/311066-upgrading-my-webpages-tot-php-742/ Share on other sites More sharing options...
requinix Posted July 10, 2020 Share Posted July 10, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/311066-upgrading-my-webpages-tot-php-742/#findComment-1579496 Share on other sites More sharing options...
Barand Posted July 11, 2020 Share Posted July 11, 2020 You actually have choice of mysqli or PDO to replace your mysql.* functions. Don't be fooled into thinking the easier route must mysqli because it's spelt almost the same. PDO is the simpler of the two interfaces. 1 Quote Link to comment https://forums.phpfreaks.com/topic/311066-upgrading-my-webpages-tot-php-742/#findComment-1579506 Share on other sites More sharing options...
gizmola Posted July 11, 2020 Share Posted July 11, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/311066-upgrading-my-webpages-tot-php-742/#findComment-1579537 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.