What PHP version still supports mysql_query()? - php

We have a PHP based website that we will migrate to another web hosting (AWS). I noticed that mysql commands, e.g. mysql_query() are still used to execute queries. The latest PHP 5.x based version no longer supports mysql_query().
What is the PHP version that we need to configure on the new web host to be able to run mysql_query()?

The mysql extension was deprecated in php 5.5.0 and removed completely from php 7.0.0
http://php.net/manual/en/function.mysql-query.php

None that you should be using. Any development should be done in 7.2 or a above. 5.x is no longer supported and should be considered not to be secure.
http://php.net/supported-versions.php
You need to go in and replace the outdated mysql_query with modern methods. Upgrading may also break from regex conversions depending on how you did them. PHP developers had years of notice before the old mysql_query functions were deprecated. On a positive note php 7.x is a lot faster and more secure.

Related

Is mysqli extension ubiquitous since PHP 5.3?

We have developed a web-application that runs on various server environments (> PHP 5.3), which currently uses the "deprecated" mysql extension to connect to mysql. Since PHP 7 however, it seems mysql is not installed by default, only the newer mysqli extension.
So we would like to convert our scripts to use mysqli, but we are concerned if the mysqli extension is not installed on "older" servers. So the question basically goes: Is mysqli generally ubiquitous since PHP version 5.3? Does anyone know from what version of PHP mysqli comes installed as default?
If some of our users are on hosts without mysqli, we would need to create a wrapper script, that detects if mysqli is available, and fall back to mysql if not.
Anyone with knowledge care to shine some light on this? Thanks
MySQLi was added with PHP 5.0
You can check if mysqli is installed by doing this:
if ( function_exists('mysqli_connect') )
// mysqli is installed

Which PHP Version To Use While Migrating from 5.3?

I am working on a project which is in php 5.3+. I need to create a separate Api which is to be deployed on same server for which i am using the Symfony2.
As i need to deploy new api on same server i want to use php 5.5+ version Now i need to upgrade my old project to new version of php and mysql as the server currently is on 5,3+. I tried the php 5.4+ and mysql 5.5+ on my local system the project works fine, but when i switched to php 5.5+ it shows me error that states mysql_connect is Deprecated.
I checked on several sites and came across a solution where i can skip the deprecated message on php 5.5 + via doing some ini settings.
Now my main concern is whether is it a right solution to migrate to php5.5+ and start new feature development out there As i need to use 5.5+ so that i wont face same deprecated issue with any other thing in future in new Apior should i migrate to 5.4+.
Kindly Reply
Upgrade to the latest 5.x branch. Do not upgrade to 7.
A new major version, means that backwards compatibility is broken. You can expected that some deprecated features are dropped. In general upgrading to a new mayor PHP version requires you to upgrade your code base.
When upgrading to a new minor version, you can expect your application to keep working. Typically new functionality is added and some functionality is deprecated, but nothing is removed.
Deprecation is a notification to indicate that functionality might be removed in an upcoming version.
The notifications are meant for you as developer, to know what you need to change to make your code ready for upgrading new major version.
On the production environment you should disable these notifications through error_reporting.
The deprecation notifications should not keep you from upgrading to a new minor version. Without this upgrade it's difficult to know what to change to make your software up to date.
Conclusion: Update to PHP 5.6. Than, when you're ready and have time, change / update your code so you're not using deprecated features. When that's done, you can upgrade to PHP 7.
The question I would ask myself if I were you is how long I would want to maintain a code base with deprecated features... my suggestion is to migrate to PHP 7 (or 5.6 minimum), upgrade projects and start new feature developments... will pay better on the long run.
The short answer is "Move to PHP 5.6 now; then move to PHP 7 later, once you've dealt (or as part of the exercise of dealing with) with all the issues that would break your code in PHP 7.
The changes from PHP 5.3 to 5.6 are not really that big. The really big changes happened between 5.2 and 5.3, but if you're on 5.3 already then you've already dealt with that. Moving up to 5.6 from there is virtually seamless.
Yes, there are some backward-compatibility breaks between every version, and yes, you must read the upgrade notes for each version before you start, but in truth, 5.4, 5.5 and 5.6 were more about adding features and increasing performance than they were about breaking things.
You specifically mention the mysql extension being deprecated in 5.5. This is true, and you will get warnings. Note, however, that these functions will still work in 5.5 and 5.6. The deprecation warning is telling you that they are considered obsolete and will be removed in the future. This has now happened in 7.0. These warnings are basically there to give you fair warning; to give you time to change your code before the next upgrade cycle. Your code will still work for now if you ignore the warnings, but you should start work immediately to fix the problem.
Fixing the problem, in the case of the mysql extension, means replacing your database code so that it uses either the mysqli or PDO extensions.
The mysqli exension is basically a drop-in replacement for the old mysql extension. There are some changes (it adds an OO interface if you want to use it, and it doesn't use a single global connection object as the old library did, so you need to pass the connection object into every call), but it's generally fairly easy to convert from one to the other.
PDO is a more advanced database library which can support a range of different database types including Mysql. It is quite different to the old extension, so converting is a more complex process. But if you can use this one, it's generally considered the preferred option.

Will mysql extension remain or will it be replaced by mysqli?

I have a old php script (very long,over a year worth of coding) running on a old pc on the lan with a old xxamp setup. The php script is so old that it contains the <?php formatting! This PC will now be replaced but the php script still needs to work. I will switch pc, update xampp to the latest version and migrate everything. I am aware that I'll have to update the old php coding but I am wondering if the whole mysql part MUST be ported to mysqli or if mysql will still exist for the next lets say 10 years. I couldnt find any information on the web.
Thanks
As stated in the comments and on the mysql_connect() page on php.net.
This extension is deprecated as of PHP 5.5.0, and will be removed in
the future. Instead, the MySQLi or PDO_MySQL extension should be used.
It's deprecated and will be removed from php in the future. There is no set date, but I can guarantee you that the use of this should stop as soon as possible. Save yourself some heartache and get cracking into PDO or MySQLi. It'll do your script the world of good!
Mysql is already deprecated. You can either use mysqli or PDO in order to handle PHP with MySql.
I'm already using PHP 5.6 on a local server, and had to rewrite parts of the class I use to connect to the DB: on 5.6, mysql extension has already been removed.
I suggest you to use PDO instead of mysqli (it's a bit more powerful, but of course, it's a personal opinion).

PHP 5.4 development server doesn't recognize mysql_connect()

I am trying to use the new development server in PHP 5.4. It runs phpinfo() just fine but on my site code and also phpMyAdmin.php they are throwing the following error:
Call to undefined function mysql_connect()
They are running through localhost:8000
php -m is showing that mysqlnd is loaded but that maybe not enough.
The OS is Windows 7
Any thoughts?
mysqlnd is the library that can be used since PHP 5.3, instead of libmysql, by 3 PHP extensions :
mysql, which provides the mysql_* functions,
mysqli, which provides the mysqli_* functons,
and pdo_mysql, which allows one to use PDO with a MySQL database.
mysqlnd by itself doesn't export any function you can use from your PHP scripts : it only provides MySQL connectivity to those 3 extensions -- which are the ones that export functions you can use.
If you want to use the mysql_* functions, you have to make sure that the mysql extension is enabled, with something that whould look like this in one of the .ini files parsed by PHP :
extension=mysql.dll
As a sidenote : the mysql_* functions should not be used anymore, especially for new projects : the mysql extension is old, and doesn't allow one to use recent (well, not that recent anymore, actually) features of MySQL.
Instead, you should be using mysqli or PDO.
It's because register_globals is no longer included as of PHP5.4, in earlier versions it was deprecated and you could force it on. The reason is because it would leave huge security gaps for hackers to exploit.
try install missing mysql module
sudo apt install php-mysqli
check if extension=mysql.so is set in php.ini after installation

Is PHP 5.3 backwards-compatible with PHP 5.2?

I'm starting to learn PHP. I would like to use PHP 5.3 because it's the newest version so far. I'm working on a project in which I'll use PHP 5.2 scripts that someone gave me.
Are they going to run just fine even though I'm using PHP 5.3?
PHP.net features a guide for upgrading from PHP 5.2.x to PHP 5.3. This includes a section on backwards compatibility.
From my experience, the transition from 5.2 to 5.3 went pretty smoothly smoothly. The only problems I had with my app was to ensure my DateTime setting were property configured in my php.ini, and filter out some overly-agressive deprecation warnings that started showing up.
No, 5.3 is not backward compatible, and by all means it shouldn't be seen as a minor version upgrade.
There is a page dedicated to incompatible changes: http://www.php.net/manual/en/migration53.incompatible.php
Also consider functions you have designed but have been accepted into 5.3. Since php doesn't support overloading or overwriting of functions, this will give an error.
For the most part, minor version releases aren't going to cause you problems. You should be okay.
Obviously, if you do have any problems, you'll want to make sure you have error_reporting set to see all errors. PHP: error_reporting
Also, check the manual for changes in 5.3 from 5.2: Migrating from PHP 5.2.x to PHP 5.3.x
There are some minor issues. Call time pass by reference are deprecated. There are new reserved words (ie. goto).
php has no backward compatibility in all version. It often removed some functions when it changed version. The problem occurs when you have to upgrade server and need to change php version but some php scripts no longer work with new php version. You also have to correct php script which is a bigger job. But if the script belong to other users rather than yours, you can't upgrade those scripts. This is a real headache situation that I'm fed up with php and switch to perl instead for backward compatibility reason.

Categories