k_nitin_r

Php 5.5 Deprecates Mysql_ Functions

Recommended Posts

Pretty soon, all the mysql_ functions that we have been using in PHP scripts could go the way of the dinosaur. Well, not literally, because there are still some PHP scripts out there that are dependent on PHP 4 so some web hosting providers still provide PHP 4 hosting. Also, we hardly have anyone running PHP 5.5 so it could be at least a few months before we are going to have to worry about getting all of our scripts updated.Now that the mysql_ functions are deprecated, what next? MySQLi and PDO_MySQL are the answer. MySQLi provides some pretty nifty features, such as being able to send multiple SQL statements to the server in one go, thus reducing the overhead of going back and forth for the execution of SQL statements, which was associated with the older MySQL API. PDO has the advantage of being able to write database-independent code, assuming that the SQL statements themselves were written with portability in mind. Both APIs are the future for PHP web developers, so what better a time to start learning than right now?

Share this post


Link to post
Share on other sites

yes this is a sad news for me, i have just searched some of my scripts and found that nearly in every single php file i have 2 mysql commands in average and this means if i have to upgrade my php then i will have serious problem with these deprected functions, by the way mysqli commands are quite good for many works.there is only one problem, i have read many times that mysqli commands should bring down cpu usage, so i have changed one of my scripts and changed all of mysql commands to mysqli commands , then i put them on my vps to see the result but after a week there is no change in server load or memory usage, i should say that the script only uses mysql for a simple login logout functionality and nothing else so maybe if i use it for a more dynamic script like CMS or forum softwares i can see differences but for a simple script i saw no difference at all !i've just checked some of my hosts php version, most of them are 5.3.x and so i don't get a warning about deprecated functions but if you run a php 5.5.x you will get warnings about those functions being deprecated, but they are still there and i think they will be removed completely from php some versions later like 5.8.x or so because removing a most used function of php will cause many scripts to stop working and that needs lots of time to inform all people about it.about PDO it seems that there is no advantage for you if you are using mysql below 4.1 (or at least this is what i have read somewhere) , the documents about this approach is still limited on the internet and it is hard to say what is the difference between pdo_mysql and mysqli, in some disscussions on the net like this : http://stackoverflow.com/questions/1408968/pdo-mysql-vs-mysqli-when-using-zend-db people say there should be a little difference or no at all in performance between these two but some other say they have found pdo_mysql to be faster than mysqli, anyway i will still stick to my mysql commands because they are fast enough for my work and if sometime i changed my php from 5.3.x to 5.5.x or later version i will also change my mysql commands to mysqli.

Share this post


Link to post
Share on other sites

You would be better off learning and using the newer MYSQLi commands as soon as possible.The older commands were deprecated for a reason and once they are deemed as deprecated, they could be dropped at any future version of MySql.Besides, it is way cooler to be using current stuff. LOL

Share this post


Link to post
Share on other sites

Lucky for me, I'm just recently starting on a new project. I was using mysql for everything when I was learning, but I'm moving over to PDO for the new project because it's seen as being more mainstream as of lately.

Share this post


Link to post
Share on other sites

Moving from the mysql functions to the mysqli functions should be an easy shift. There was a mention on a blog that the mysql functions are 'lighter' and so execute quicker when compared to the mysqli functions, though I have not seen any benchmarks to compare the two. I think that it is in alignment with the observations of the JDBC thin drivers for Oracle as opposed to the OCI JDBC drivers that provide much more functionality than the thin drivers do. The mysqli API provides both an object oriented and a procedural approach to using the code. A downside is that a malicious user can do a whole lot more by using SQL injection with scripts that use mysqli so there's a problem that surfaces if a novice implements a PHP based application with mysqli coded in the same manner as the insecure applications that were build with the mysql extension. I don't mean to say that the extensions themselves are insecure but if the same insecure code were to be altered to use mysqli, there is a whole lot more than a hacker could do to a site. Fortunately, some web servers are configured to lock down the application such that malicious requests are filtered out and repeated attempt would lead to the IP address being barred from accessing the server. It could happen to legitimate requests too, but it helps to know that there is something in place that can prevent attacks against an application built by a novice.

Share this post


Link to post
Share on other sites

Moving from the mysql functions to the mysqli functions should be an easy shift. There was a mention on a blog that the mysql functions are 'lighter' and so execute quicker when compared to the mysqli functions, though I have not seen any benchmarks to compare the two. I think that it is in alignment with the observations of the JDBC thin drivers for Oracle as opposed to the OCI JDBC drivers that provide much more functionality than the thin drivers do. The mysqli API provides both an object oriented and a procedural approach to using the code. A downside is that a malicious user can do a whole lot more by using SQL injection with scripts that use mysqli so there's a problem that surfaces if a novice implements a PHP based application with mysqli coded in the same manner as the insecure applications that were build with the mysql extension. I don't mean to say that the extensions themselves are insecure but if the same insecure code were to be altered to use mysqli, there is a whole lot more than a hacker could do to a site. Fortunately, some web servers are configured to lock down the application such that malicious requests are filtered out and repeated attempt would lead to the IP address being barred from accessing the server. It could happen to legitimate requests too, but it helps to know that there is something in place that can prevent attacks against an application built by a novice.


Regarding efficiency, I had seen a few benchmarks that showed they are. There were some things that the regular MySQL was faster on as well, but it was related to being a situation of security. I'm not sure where the benchmarks are now (I was actually trying to research PDO vs MySQL) though.

Share this post


Link to post
Share on other sites

One way to improve the efficiency of your mysql coding is to consider using Prepared statements.

See here: http://de1.php.net/manual-lookup.php?pattern=manuaqli.prepare.php〈=en&scope=404quickref

It is, of course, mysqli statement which makes a more secure code and also runs faster since the query is only compiled once instead of every time the code is acted upon. Great for queries inside a loop.

Edited by jlhaslip

Share this post


Link to post
Share on other sites

One way to improve the efficiency of your mysql coding is to consider using Prepared statements.

 

See here: http://de1.php.net/manual-lookup.php?pattern=manuaqli.prepare.php〈=en&scope=404quickref

 

It is, of course, mysqli statement which makes a more secure code and also runs faster since the query is only compiled once instead of every time the code is acted upon. Great for queries inside a loop.

 

I haven't found a solid answer to this (or I'm searching wrong) but maybe you'll know...

 

When we look at "query caching," what happens when the query is dynamic? For example let's say we do "select name from people where ID='3'"

 

Does the query cache save the results for every query that comes through, so let's say we did ID 3 first, then reloaded and did ID 5, would it save the results for both 3 & 5? Or am I misunderstanding what the cache part of it is?

Share this post


Link to post
Share on other sites

The dynamic queries are cached , and your sample code above would be cached, however, there are conditions under which these queries get flushed from the cache, so they recommend using the cache for queries where the tables do not get altered (for example) and where the data is static.
Read more here: http://forums.xisto.com/no_longer_exists/

Edited by jlhaslip

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now