PHP with mysqli-oriented process open connection close MySQL database

Source: Internet
Author: User

The code is as follows:

1<meta http-equiv= "Content-type" content= "text/html" charset= "Utf-8"/>23<form method= "POST" action= "<?php Echo iconv (" GB2312 "," UTF-8 ", Htmlspecialchars ($_server[' php_self ']); /using the Htmlspecialchars () function to?> the output of the ">4Server address: <input type= "text" name= "Mysqlip"/>5<br/>6Server account: <input type= "text" name= "Mysqluser"/>7<br/>8Server password: <input type= "password" name= "Mysqlpassword"/>9<br/>Ten<input type= "Submit" value= "connect to MySQL"/> One</form> A<?PHP - if($_server[' Request_method ']== "POST") {//If the page is submitted as a post -     $servsername=$_post[' Mysqlip ']; the     $username=$_post[' Mysqluser ']; -     $password=$_post[' Mysqlpassword ']; -     Mysqli_connect($servsername,$username,$password); -     if(Mysqli_connect_error()){//If you determine if the link is successful!  +         Echo"Connection Failed! ".Mysqli_connect_error(); -}Else{ +         Echo"The connection was successful!" "; A         Echo"<br/> The database address you are connected to:".$servsername; at         Echo"<br/> the database account you are connected to:".$username; -         Echo"<br/> The database password you are connected to:".$password; -     } -     if(Mysqli_connect_error()){//If you determine the link succeeds, then close the database!  -         Echo<br/> the database being connected is not detected! Unable to close the database! "; -}Else{ in         Echo"<br/> has closed the database connection! "; -     } to } +?>

The first if judge whether the page has been post method to submit data, to prevent the error when assigning a value;

The second if the database is successfully connected to the error, the client is judged to return;

The third if the database has been successfully connected error, the decision to close the connection;

Also, some servers will have to submit not to go up, here we do code conversion, the page is UTF-8 we put $_server[' php_self '] the path obtained by default may be GB2312, with iconv function encoding conversion utf-8!

Online test Instance Address: Http://blog.z88j.com/mysql/mysqli process-oriented connection database. php

PHP with mysqli-oriented process open connection close MySQL database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.