deprecated mysql extensions

netplus21
netplus21 used Ask the Experts™
on
Hello,

I have an outdated php/mysql script that isn't working, due to a server software upgrade.

Here are some lines from the error log:

[03-Apr-2017 04:05:16 UTC] PHP Deprecated:  mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/intelli1/public_html/metrics1/start.php on line 18
[03-Apr-2017 04:05:16 UTC] PHP Deprecated:  Function mysql_numrows() is deprecated in /home/intelli1/public_html/metrics1/library.php on line 135

This is line 18
$connection=mysql_connect($sqlserver,$db_login,$db_pass) or die('Could not connect to the database server');



and this is line 135
for($i=0;$i<mysql_numrows($result);$i++){


I am not a programmer, please give me instructions on what changes need to be made to those lines.

If the changes don't work, what further information would be needed?

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016
Commented:
You need a programmer.  And you probably need a budget.  This is not a small project.  It's been a known issue for several years.  This article tells what the programmer must understand and must do to keep your application running.
https://www.experts-exchange.com/articles/11177/PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html

Now having said that, you might be able to get some short-term relief by turning off the "deprecated" messages, but this is like putting black electrical tape over the warning light on your car's dashboard.  It will mask the problem, but not fix the problem, and you really want to fix the problem before deprecation turns fatal.  There is no longer any existing supported version of PHP that still includes MySQL, so it's time to get that programmer and act now!

You can add this to your php.ini file, but if you do that and the problem seems to disappear, you're on borrowed time, so get an expert involved right away.
 error_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE

Open in new window

FWIW, I recently looked at an application that belonged to a well-known technology non-profit.  They had over 400 instances of the MYSQL extension, a set of hard-wired spaghetti code dependencies that would take forever  to fix.  If you could fix and test* one instance per hour, you're looking at 10 weeks of work!  It's realizations like this that lead us in the direction of database abstraction layers and application frameworks.  You're lucky - you caught this in time to do something about it!

* Nearly impossible testing is one of the leading reasons that PHP has removed the MySQL extension.  You can't mock the connection, so you can't readily create a test environment.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial