I have been told that the mysql_
extension is now deprecated in the current version of PHP and will be removed at some point.
What should I use instead of this and how?
For nearly all my queries I use it.
For example:
$result = mysql_query($query);
if (!$result) die ("Database access failed: " . mysql_error());
$rows = mysql_num_rows($result);
According to the PHP
Manual, you should use any of the following:
To be clear though, neither of these is a mere substitute for mysql_num_rows()
. Your code must eventually be rewritten entirely to use the MySQLi or PDO API in lieu of mysql_*()
.
Personally, I now use the MySQL Improved extension.
If you choose to use it in the procedural way it can be used in a very similar manner to how you're currently using the old MySQL extension.
Example (MySQL):
$result = mysql_query($query);
if (!$result) die ("Database access failed: " . mysql_error());
$rows = mysql_num_rows($result);
Example (MySQL Improved):
$result = mysqli_query($query);
if (!$result) die ("Database access failed: " . mysqli_error());
$rows = mysqli_num_rows($result);
However, I use MySQL Improved in an object orientated manner.
More information can be found here: http://www.php.net/manual/en/book.mysqli.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With