Updating deprecated code for MySQL 5.5.+
Quote:
Originally Posted by
traq
I would highly recommend using
MySQLi instead on the mysql extension -
mysql is deprecated and
should not be used in new projects. MySQLi (or PDO) has been the recommended extension since 2004.
--------------------------------------------------
# If at all possible, you should avoid using the mysql_* functions. #
Existing code should be updated to avoid performance and security problems.
I haven't been on the forum for awhile. I had been checking something on php.net and noticed the warning about mysql_* functions being deprecated, so I came to DD & found traq's post. I am dumbfounded that I could not have heard anything about this until now. I didn't even start using php until about 2008. The host for all my client sites uses MySQL 5.5.32 so I fear that any day all my sites could suddenly stop working.
I am far from a php expert, but it appears I have to rewrite the code for all my sites... a HUGE undertaking. I am wondering if it is just a case of doing a search-and-replace substituting mysqli for mysql everywhere it occurs. For example, here are the typical ways I use mysql...
Code:
$connection = mysql_connect($server,$user,$pass) or die("Couldn't connect to $db_name database.");
$db = mysql_select_db($db_name, $connection) or die("Couldn't find $db_name database.");
$result = mysql_query($sql,$connection) or die("Couldn't execute $sql query. <br> mysql error: ".mysql_error());
while($var = mysql_fetch_assoc($result)){ ?>
If I change to mysqli in the connection string, does that mean the code will break anywhere I used mysql within that code set? ie. I will have to change ALL code all at once for an entire site or it won't work?
Can I just add the "i" to mysql or are there other changes required to effect the update? Is mysql the only thing being deprecated? I might as well do everything at once. Thanks very much.
BTW it took me about an hour to get on the forum. First it told me my password was bad so I tried the lost password routine. I couldn't get past the CAPTCHA even though I was entering the right characters. So then I tried to re-register, but it said my email was in use, so I tried lost password again and this time was able to change the pw. I logged in but got logged out again before I could submit my question. What is going on??!