不推荐使用的函数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
.
最近我的托管更新了它的php版本后我的网站出错了,这里是错误信息 p>
不推荐使用:函数mysql_db_query()在第13行的/my_path/file.php中已弃用
Deprecated:函数mysql_db_query()在第14行的/my_path/file.php中已弃用\ n code> pre>
以下是 file.php的代码 code> p>
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')“)或死亡(”0用户在线“); //第13行显示错误
mysql_db_query($ db,“DELETE FROM online WHERE timestamp&lt; $ timeout”)或die(“0 Users online”); //这是显示错误的第14行
code> pre>
是否有此错误的解释以及如何解决? 〜谢谢 p>
注意:我知道 mysqli code>和 pdo code>但由于我的网站主要依赖 mysql code>并且需要几个月才能进行重大更改,所以请您坚持使用 mysql code>。 p>
div>
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:
Downgrade back to PHP 5.4.
That doesn't sound like an option, given that your webhost did the upgrade.Just do the work.
Honestly, it's not that big a deal to switch from themysql_
functions to themysqli_
functions. The APIs are very similar; the main difference is that thei
functions require the connection variable to be passed. But that's hardly an insurmountable problem. Converting tomysqli
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).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.