0

I'm a little dim when it comes to this and can replace where advised but this produces further errors. If someone could assist it would be appreciated.

Ignoring the error fails also (and from what I read shouldn't be used anyway).

I replaced with mysqli_connect and added $sys_dbname but then failed again with the error check for the mysql_select_db which reported requiring a string given. Changed to mysqli_select_db and still the same output.

Can someone quickly fix the code below for me? Thanks Dave

function db_connect() 
{
global $host,$user,$pwd,$errstr,$sys_dbname,$port;
$strhost=$host;
if($port && $port!=3306)
    $strhost=$strhost.":".$port;
$conn = mysql_connect($strhost,$user,$pwd);
if (!$conn || !mysql_select_db($sys_dbname,$conn)) 
{
  trigger_error(mysql_error(), E_USER_ERROR);
}
return $conn;
}

function db_close($conn)
{
return mysql_close($conn);
  • 2
    deprecated is not an error. It's a WARNING. And we are not a code translation service. I suggest you start reading: http://php.net/mysqli_connect – Marc B Sep 08 '15 at 18:56
  • I appreciate it has been answered elsewhere for the initial error but after correcting the mysql with mysqli the if statement then breaks with an error requiring a string. There is no mention of this on other searches related the changing to mysqli. Also, as mentioned trying to ignore the error with error_reporting(E_ALL ^ E_DEPRECATED); doesn't do anything, I still get errors. – Big Dave G Sep 08 '15 at 19:47
  • @Marc B, I appreciate you are not a code translation service but everyone knows how to do this but not willing to give first timers assistance other than "It's been answered before". Like trying to program past "Hello World", once you get to that there is no further assistance. Thanks for looking though. – Big Dave G Sep 08 '15 at 19:50
  • then at least tell us EXACTLY what error message you're getting. there's far too many people who expect us to do their jobs for them, and don't bother doing ANY debugging/fixing themselves. – Marc B Sep 08 '15 at 19:51
  • Thanks Marc, after changing: $conn = mysql_connect($strhost,$user,$pwd); To: $conn = mysqli_connect($strhost,$user,$pwd,$sys_dbname); Line 10 error: mysql_select_db() expects parameter 2 to be resource, object given – Big Dave G Sep 08 '15 at 19:57
  • $conn is an object, therefore, which means you're using mysqli_connect elsewhere to create $conn. you can **NOT** mix the mysql_*() and mysqli_*() functions together. they are not interchangeable/intercompatible. – Marc B Sep 08 '15 at 20:23
  • I have reverted back to 5.4 as the file has too many mysql commands for me to get my head around tonight. The DB was built using phprunner some years ago so I guess I will need to deploy a new web front-end using latest PHP. Thanks for your comments and remember, we're not all experts :-) – Big Dave G Sep 08 '15 at 20:58

0 Answers0