-4

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 start.php on line 18
[03-Apr-2017 04:05:16 UTC] PHP Deprecated:  Function mysql_numrows() is deprecated in library.php on line 135

This is line 18 onwards

$connection=mysql_connect($sqlserver,$db_login,$db_pass) or die('Could not connect to the database server'); 
$db = mysql_select_db($db_name, $connection) or die ("Unable to select database."); 


$sql="SELECT IP,Date FROM users WHERE IP='$IP' ORDER BY Date DESC LIMIT 1";

and this is line 135 onwards

for($i=0;$i<mysql_numrows($result);$i++){
        for($j=0;$j<mysql_num_fields($result);$j++){
                        $ranges[$i][mysql_field_name($result,$j)] = mysql_result($result,$i,mysql_field_name($result,$j));
                    }//end inner loop
                }//end outer loop

I am not a programmer, can this be solved with a find replace?

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

Thanks!

Jan
  • 42,290
  • 8
  • 54
  • 79
Netrunner21
  • 51
  • 2
  • 9
  • 4
    It can't be solved just with find and replace. You have to swap to mysqli_* or PDO which does not have the same syntax. – LoïcR Apr 12 '17 at 11:16
  • `mysql_numrows()` isn't even a core function; it's missing an underscore `mysql_num_rows()` for one thing. – Funk Forty Niner Apr 12 '17 at 11:18
  • @Sakuto: I guess OP meant this when saying `find and replace`. – Jan Apr 12 '17 at 11:18
  • 3
    These are only warnings, not errors. These are not the reason why your script does not work. And no, transitioning over to mysqli or PDO cannot be done via search and replace. – Shadow Apr 12 '17 at 11:19
  • 2
    _If the changes don't work, what further information would be needed?_ Well you could start by telling us how much you are prepared to pay for the necessary recoding – RiggsFolly Apr 12 '17 at 11:19
  • You might try https://www.phpclasses.org/blog/package/9199/post/3-Smoothly-Migrate-your-PHP-Code-using-the-Old-MySQL-extension-to-MySQLi.html but if you are not a programmer I can only offer you good luck and say. Make sure you backup your databases before trying this – RiggsFolly Apr 12 '17 at 11:31

1 Answers1

-2

With the new mysqli_connect there are 4 arguments, the first 3 are the same as mysql_connect - $host, $login, $password and the 4th is $db.

This omits the need to include

$db = mysqli_select_db($db_name, $connection);

I would suggest creating a function

function ConnectToDB(){
     return mysqli_connect($host, $login, $pass, $db);
}

You can then replace all of your mysql_connects with a call to this function.

ConnectToDB();
  • This in no way solves this OP's whole problem it only moves the error to the first attempt to query the database as all database access calls wil be based on a deprecated `mysql_` api – RiggsFolly Apr 12 '17 at 11:22
  • a) This is not the only change necessary b) Which part of `I am not a programmer, can this be solved with a find replace?` did you not understand? – ccKep Apr 12 '17 at 11:23
  • The question has entirely changed upon my answering – ADoorMarkedPirate Apr 12 '17 at 11:24
  • No, been the same question all along, only formatting has changed – RiggsFolly Apr 12 '17 at 11:24
  • 1
    You can see the edit history ([link to initial version](http://stackoverflow.com/revisions/43368037/1)), it has not... only formatting changes to code blocks. – ccKep Apr 12 '17 at 11:24