不推荐使用的函数mysql_db_query错误

Recently after my hosting updated its php version i've got error in my website and here is the error message

Deprecated: Function mysql_db_query() is deprecated in /my_path/file.php on line 13 
Deprecated: Function mysql_db_query() is deprecated in /my_path/file.php on line 14

Here is the code of the file.php

require_once("db.php"); // connect
$timeoutseconds = 100;
$timestamp=time();
$timeout=$timestamp-$timeoutseconds;


mysql_db_query($db, "INSERT INTO online VALUES ('$timestamp','$REMOTE_ADDR','$PHP_SELF')") or die("0 Users online"); // this is line 13 that shows error

mysql_db_query($db, "DELETE FROM online WHERE timestamp<$timeout") or die("0 Users online"); // this is line 14 that shows error

Is there explain for this error and how can fix it ? ~ thanks

Note : i know about mysqli and pdo but can't shift to any since my website depends mainly on mysql and will needs months to do major changes so please can you stick with mysql.

You will need to upgrade to MySQLi or even better, PDO. However, I understand that you may need a solution as of right now because you have a live website and you want to hide errors (yet the website will still work). But, you will need to consider upgrading because theses functions will be removed in a near future.

Add this to your main file at the top.

error_reporting(E_ALL ^ E_DEPRECATED);

or

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

Yes, the mysql functions have been deprecated in PHP 5.5.

You can't "fix" this -- it's how things are.

Your options are:

  1. Downgrade back to PHP 5.4.
    That doesn't sound like an option, given that your webhost did the upgrade.

  2. Just do the work.
    Honestly, it's not that big a deal to switch from the mysql_ functions to the mysqli_ functions. The APIs are very similar; the main difference is that the i functions require the connection variable to be passed. But that's hardly an insurmountable problem. Converting to mysqli is actually pretty simple if you put your mind to it. It certainly won't take months (unless your code really is a disaster zone where any minor change would take months).

  3. Ignore the warnings.
    They are only warnings; your program will continue to run despite them, so just set PHP's error handling to ignore deprecation warnings, and they'll disappear. However, don't think this lets you off the hook -- when your webhost upgrades next time and the functions have been completely removed from the language, it will be a lot harder to fix, and a lot more urgent. Seriously, do the work now: you'll save yourself a mountain of pain later.