首页 > php教程 > php手册 > php判断数据库是否连接成功的测试例子,php判断数据库例子

php判断数据库是否连接成功的测试例子,php判断数据库例子

WBOY
发布: 2016-06-13 08:54:29
原创
1054 人浏览过

php判断数据库是否连接成功的测试例子,php判断数据库例子

php判断数据库是否连接成功的测试例子

如果出现数据库配置不正确的错误,请看php与mysql的配置教程:

win7系统下如何配置php-Apache-mysql环境 http://www.cnblogs.com/myall/p/4744837.html

<form action="" method="post">
    <select name="host">
        <option value="localhost" selected>localhost</option>
        <option value="127.0.0.1">127.0.0.1</option>
    </select>
    <br><br><span>
    user</span>:<input type="text" name="user" value=""><br><br><span>
    pwd </span>:<input type="password" name="pwd" value=""><br><br>
    <input type="submit" value="connent">
    <input type="reset" value="reset">
</form>
<?<span>php 
    </span><span>error_reporting</span>(~<span>E_ALL</span><span>);
    </span><span>$host</span> = <span>$_POST</span>['host'<span>];
    </span><span>$user</span> = <span>$_POST</span>['user'<span>];
    </span><span>$pwd</span> = <span>$_POST</span>['pwd'<span>];
    </span><span>if</span>(<span>isset</span>(<span>$_POST</span>['host']) && <span>isset</span>(<span>$_POST</span>['user']) && <span>isset</span>(<span>$_POST</span>['pwd'<span>])){
        </span><span>if</span>(<span>strlen</span>(<span>$host</span>)<1 or <span>strlen</span>(<span>$user</span>)<1 or <span>strlen</span>(<span>$pwd</span>)<1<span>){
            </span><span>echo</span> "请完善相关数据库链接信息。"<span>;
            </span><span>exit</span>(0<span>);
        }
        </span><span>$conn</span> = <span>mysql_connect</span>(<span>$host</span>, <span>$user</span>, <span>$pwd</span>) or <span>die</span>("Error-数据库连接失败!"<span>);
        </span><span>if</span>(<span>$conn</span><span>){
            </span><span>echo</span> "OK&mdash;数据库连接成功!"<span>;
        }
    }
</span>?>
登录后复制

 

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板