Learn the specific usage of PHP functions for establishing and disabling database connections _ PHP Tutorial

Source: Internet
Author: User
Understand the usage of PHP functions for establishing and disabling database connections. Mysql_connect () resourcemysql_connect ([stringhostname [: port] [: pathtosocket] [, stringusername] [, stringpassword]) for establishing and disabling database connections in PHP are optional.

Mysql_connect () for establishing and disabling database connections in PHP ()

Resource mysql_connect
([String hostname
[: Port] [:/path/to/socket]
[, String username] [, string password])

All parameters are optional.

Example:

 
 
  1. @mysql_connect("localhost"
    , "user", "password")
  2. or die("Could not connect
    to mysql server!");

Note: The @ symbol indicates any error message caused by a failed attempt. you will see the error message specified in die.

Note: When connecting to multiple mysql databases, you must specify the link ID of each connection, as shown below:

 
 
  1. $link1 = @mysql_connect
    ("server1", "user", "password")
  2. or die("Could not connect to
    mysql server!");
  3. $link2 = @mysql_connect
    ("server2", "user", "password")
  4. or die("Could not
    connect to mysql server!");

Mysql_pconnect () for establishing and disabling database connections in PHP ()

 
 
  1. resource mysql_pconnect
    ([string hostname [:port]
    [:/path/to/socket][,string
    username] [,string password]])

Different from mysql_connect (), the existing link is first searched for and is created only when the link does not exist.
Note that you do not need to display the close connection (mysql_close (), because the connection will be placed in the pool, it is called a persistent connection.

Mysql_close () for establishing and disabling database connections in PHP ()

 
 
  1. boolean mysql_close
    ([resource link_id])

Closing the connection is not required because it can be handled by mysql garbage collection.
If link_id is not specified, the latest link is closed.


Evaluate () resourcemysql_connect ([stringhostname [: port] [:/path/to/socket] [, stringusername] [, stringpassword]) all parameters are optional...

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.