Can PHP 5.4 run on PHP 5.3 configured server - php

First of all, I am a novice web developer.
My question is "A website developed with PHP 5.4 can run on PHP 5.3 configured server?"
(Detail Description)
I configure myself Apache 2.4, MySQL 5.6 and PHP 5.4.12 on Windows. Everything's ok. But the errors occur when I changed my website folder to another machine which is configured with WAMPserver. This WAMPserver is configured with Apache 2.2.11, PHP 5.3 and MySQL 5.1.36.
I install MySQL 5.6 on this machine and database is successfully connected. But the "Parse error occur to the code" such as
$country = mysql_fetch_row(queryMySQL("----"))[0];
In addition, it showed other errors such as "Table 'emp.productcateogry' doesn't exist".
Please, give me some suggestions.

The short answer is: no, you should not expect it to, especially if using the new features of PHP 5.4 within your code.
The specific error you are referring to with:
Parse error occur to the code
is because the line
$country = mysql_fetch_row(queryMySQL("----"))[0];
is using the new feature:
Function array dereferencing
Which, prior to PHP 5.4, had to use a temporary variable in order to access a specific index of the return, ie:
$country_temp = mysql_fetch_row(queryMySQL("----"));
$country = $country_temp[0];
Now, being that you are a novice developer, there are a few things you should note. The first and most important being that mysql_ functions are deprecated giving the note:
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.
In other words, use PDO if wanting to use prepared statements, or MySQLi if not. Another advantage of using PDO and obtaining only one column as you are in the example code is that once you are connected, you can use the function PDOStatement::fetchColumn() to obtain only one column like you are trying to do now.
Anyways, I hope this explanation helps you understand why you can't go back to PHP 5.3.x if using specific PHP 5.4 abilities - and also some understanding of how to improve your database connection and available functions that can help you get your desired result without using the "array dereferencing" that is provided with PHP 5.4. ^^

Related

Can't get legacy versions of PHP to use MySQL under Plesk and CentOS

I am changing my hosting provider and migrating from cPanel to Plesk. Everything is nice and I am exited but I can't get old PHP scripts working which still use MySQL instead of MySQLi or PDO.
Plesk lets different accounts or domains use different versions of PHP. Fortunately even older versions that still recognize MySQL are available (5.4, 5.5, 5.6) and I have actually managed to make one of my domains to use PHP 5.6 but although it works there, MySQL is still not available. MySQLi is working with PHP 5.6 but all point of downgrading PHP was to get MySQL working. It simply complains: 'Call to undefined function mysql_connect()'.
As far as I can see mysql extension is installed. phpinfo() shows sections of mysql and mysqli and mysqlnd and even pdo_mysql. mysql.so is there at /opt/plesk/php/5.6/lib64/php/modules.
I have tried all the options in Plesk and I have edited the ini files (extension=mysql.so) but no progress. I have spent all day already. Have also tried different handlers.
One thing that I have noticed is on the phpinfo() page. 'Configure Command' section contains among the other strings, the following: '--without-mysql'. I don't see a way in Plesk to remove this. And I don't see a way to change configure options for PHP. Is this the reason why mysql_ functions don't work? How to solve this? I got it working easily with cPanel but Plesk is new to me and Google has not been helpful today. Please advice!

What PHP version still supports mysql_query()?

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.

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.

Continually getting "PHP Fatal error: Call to undefined function mysql_connect()" in iis 7

I am very new to web development but am required to use iis 7 and php to pull data from a remote mysql database to be displayed in a series of webpages.
I installed iis 7 along with php fine and can run phpinfo() through a .php file from a browser by going to localhost/testphp.php , however, when I tried to connect to a mysql server using the function mysql_connect in another .php file I got the error in the title.
I am running php 5.6.15 and can't find much in the way of an answer for this.
I also don't seem to have a php.ini file (let alone know if I should have one) and phpinfo() tells me that my loaded configuration file is "(none)".
I'm at my wit's end trying to find a solution to this with as little experience as I have. Does anyone know how to solve this problem? If so I would much appreciate any help I can get.
Thank you!
As of PHP 5.5, MySQL is deprecated. http://php.net/manual/en/migration55.deprecated.php
You should go for alternative ( MySQLi for example ), or use older version of PHP.
As mentioned a couple of times the old MySQL stuff is deprecated. I would actually suggest looking at PDO instead of MySQLi too.
To check for the API you are wanting, check for the following in phpinfo():
Should be a section called "mysql" with something like:

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).

Categories