Home >Backend Development >PHP Tutorial >PHP test example to determine whether the database connection is successful, PHP to determine the database example_PHP tutorial

PHP test example to determine whether the database connection is successful, PHP to determine the database example_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:08:381263browse

Test example of php to determine whether the database connection is successful, php to determine whether the database connection is successful

php test example to determine whether the database connection is successful

If there is an error that the database configuration is incorrect, please see the configuration tutorial of php and mysql:

How to configure the php-Apache-mysql environment under win7 system 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>?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1053810.htmlTechArticlephp test example to determine whether the database connection is successful, php determines the database example php determines whether the database connection is successful test example if An error that the database configuration is incorrect occurred, please...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn