PHP mysql_connect () function

Source: Internet
Author: User

Definition and usage

The mysql_connect () function opens a non-persistent MySQL connection.

Grammar
Mysql_connect (Server,user,pwd,newlink,clientflag)
parameter description
server

Optional. Specifies the server to connect to.

Can include a port number, such as "Hostname:port", or a path to a local socket, such as ":/path/to/socket" for localhost.

If PHP directive mysql.default_host is undefined (by default), the default value is ' localhost:3306 '.

user is optional. User name. The default value is the user name of the server process owner.
pwd is optional. Password. The default value is a blank password.
newlink Optional. If you call mysql_connect () for the second time with the same parameters, no new connection will be made and the connection ID that is already open will be returned. The parameter New_link changes this behavior and causes mysql_connect () to always open a new connection, even when mysql_connect () was previously called with the same parameters.
clientflag

Optional. The Client_flags parameter can be a combination of the following constants:

  • Mysql_client_ssl-using SSL encryption

  • Mysql_client_comp RESS-Use compression protocol

  • Mysql_client_ignore_space-interval after function name

  • Mysql_client_interactive- Allow interaction timeout before closing a connection inactivity time

return value

If successful, returns a MySQL connection ID, which fails to return FALSE.

Hints and Notes

Note: At the end of the script, the connection to the server is closed, unless Mysql_close () has been explicitly called before.

Tip: To create a persistent connection, use the Mysql_pconnect () function.

Example
<?php$con = mysql_connect ("localhost", "Mysql_user", "mysql_pwd"), if (! $con) {die (' Could not connect: ') mysql_error (  )); }//some code ... mysql_close ($con);? >


PHP mysql_connect () function

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.