检查主机是否存在于MySQL / PHP中 [英] Check host exist in MySQL/PHP

查看:115
本文介绍了检查主机是否存在于MySQL / PHP中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



假设我想通过PHP连接到不同PC的数据库。所以我可以做这样的事情,



Hi all,

Say I want to connect to a database in a different PC through PHP. So I could do something like this,

<?php
    $username = "root";
    $password = "sa";
    $host = "192.168.2.20";
    $database = "database";

    $link = mysql_connect($host, $username, $password);
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }
                
    mysql_select_db ($database);
?>





192.168.2.20 IP(或者PC)存在于网络中,并说它关闭并尝试如上所述连接到它。在通过上面的PHP代码段报告连接错误之前,它会重试直到连接超时。



我想知道数据库在惰性之前可用数据进入它并通知用户他/她是否不能这样做。希望大家都清楚我的要求。



提前谢谢:)



That 192.168.2.20 IP (or the PC) exist in the network, and say it shutdown and try to connect into it as above. Before report the connection error by the above PHP code segment, it''ll retry till the connection timeout.

I want to find out that the database is available before inert data into it and notify to the user if he/she cannot do that. Hope you all are clear with my requirement.

Thanks in advance :)

推荐答案

用户名
= root;
username = "root";


密码 = SA;
password = "sa";


host = 192.168.2.20\" ;
host = "192.168.2.20";


这篇关于检查主机是否存在于MySQL / PHP中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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