Connection between PHP and MYSQL database _ MySQL-mysql tutorial

Source: Internet
Author: User
Tags mysql connect pconnect
Links between PHP and MYSQL databases: bitsCN.com among the many functions in MYSQL database, there are two functions used to connect, namely, MysQL-connect () and MySQL _ pconnect (). Syntax:

Int MySQL-connect (string [hostname] (: [Port, string [username], string [password]) int MySQL _ pconnect (string [hostname] (: [Port, string [username], string [password]) after the connection is successful, both functions return a connection number. if the connection fails, return a false value. In the parameter, the host name (hostname) can contain the port number of the database service. The default port number is usually used. If all parameters are specified, the default host name is "localhost". The username is the database administrator. the default host name is "root" and the Password is blank.

When you use MysQL connect () to establish a connection, the established connection is automatically closed after the database operation is completed, unless the connection has been forcibly closed by MySQL-close () before this. MysQL-pconnect () automatically checks whether a connection is established using the same host name, user name, and password. If yes, the connection ID is used directly. In addition, using MySQL-pconnect () is a stable and persistent connection that will not be stopped because of the database operation. And will not be terminated by the function MySQL_commect.

Program example:

<? Php $ connect = MySQL_connect ('localhost', 'username', 'password ');

Echo "$ connect ";

?>

The program running result is: (1 ). This indicates that the program has been connected to the database.

Source: Jingan network http://host.zzidc.com/reprinted note

BitsCN.com

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.