Results 1 to 4 of 4
Dec 13, 2013, 01:47 #1
- Join Date
- Jul 2005
- West Springfield, Massachusetts
- 187 Post(s)
- 2 Thread(s)
STOP using mysql - migrating to procedural mysqli
If you haven't already, you should migrate from PHP's deprecated mysql to mysqli (MySQL Improved) or PDO (PHP Data Objects) now!
Here in the SitePoint forums we still see a lot of code examples using PHP mysql functions despite the fact that they have been deprecated as of PHP version 5.5 start:rfc:mysqldeprecation
True, they may only throw E_DEPRECATED warnings for now, but at some point they will most likely become unsupported. You have been given notice, and unless you have an old version of MySQL (before version 4.1) why wait until your code breaks?
There are many strong reasons why your database code should be using PDO - Migrate From the mysql extension to PDO - perhaps the most compelling reason being that the code can work with databases other than MySQL.
But even if you only feel comfortable writing procedural code, you really should at least be using mysqli and not using deprecated mysql
Avoid the Original MySQL Extension, Part 1
Avoid the Original MySQL Extension, Part 2
The mysqli functions are in some ways a mid-way between depecated mysql and PDO, many functions can be written in either Procedural or Object Oriented style.
Many of the the mysqli functions are the same as the now deprecated mysql functions. Though there may be some differences in parameters and/or syntax and/or return values, in many cases you will probably simply need to add the "i" without needing to do any non-trivial code rewriting to use them. Check the documentation to be sure.
To keep things simple, this thread does not cover:
- OOP mysqli
- other advantages mysqli has over deprecated mysql eg. prepared statements
its focus is aimed at migrating deprecated procedural mysql to procedural mysqli
I've stopped using the mysql functions when writing new code for some time now. But just how hard is it to migrate old code?
To find out I used my text editor to find files in my site that used "mysql_" functions.
Interestingly, not only did I find instances of its use in my old code, but I discovered that current releases of both WordPress and phpMyAdmin still use deprecated mysql code. i.e.
To be fair. I won't attempt to judge their decisions, as indeed I know WordPress has been working on this for some time - Use PDO or mysqli for MySQL queries when available
In fact, if you want to help, consider trying WP DB Driver
I won't get into how I feel about turning off E_DEPRECATED and using @ error suppression, but I'll say that I won't be using either in my own code unless at some point I find that I have no other choice.