php mysql_connect警告禁用 [英] php mysql_connect Warning disable

查看:94
本文介绍了php mysql_connect警告禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有php脚本,应该尝试连接到本地站点中的数据库.如果本地数据库不可用,则应尝试连接到远程服务器上的数据库.

I have php script wich should try to connect to DB in local site. If the local DB is not available it should try to connect to DB on remote server.

$dblink = mysql_connect(DBHOST_LOCAL, DBUSER, DBPASS) or $RC = 1;
if($RC) {
    $dblink = mysql_connect(DBHOST_REMOTE, DBUSER, DBPASS) or die('Could not connect'.mysql_error());
}

问题是,如果第一次连接失败,我不想在页面上显示警告消息.有什么方法只能针对mysql_connect()函数禁用警告消息吗?

The problem is that I don't want to display Warning message on page if connection faild the first time. Is there any way to disable the warning message only for mysql_connect() function?

推荐答案

是的,像这样添加一个@符号以禁止显示警告/错误消息,然后自己执行一次错误一次:

Yes, add an @ sign like so to suppress warning / error messages, then do the error once your own:

$dblink = @mysql_connect(DBHOST_LOCAL, DBUSER, DBPASS);

if (!$dblink) 
{
    $dblink = @mysql_connect(DBHOST_REMOTE, DBUSER, DBPASS);                  
}

if (!$dblink)
{
    $message = sprintf(
        "Could not connect to local or remote database: %s",
        mysql_error()
    );
    trigger_error($message);
    return;
}

请注意,然后您需要处理所有错误报告.这样的代码很难调试,以防万一您犯错了.

Take care that you need to handle all error reporting your own then. Such code is hard to debug in case you make a mistake.

这篇关于php mysql_connect警告禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆