Learn about PHP's specific function usage for establishing and closing database connections _php Tutorial

Source: Internet
Author: User

PHP mysql_connect () to establish and close database connections

Resource Mysql_connect
([string hostname
[:p ORT] [:/path/to/socket]
[, String Username] [, String password]])

All parameters are optional

Example:

 
  
  
  1. @mysql_connect ("localhost"
    , "User", "password")
  2. Or Die ("Could not Connect

Note that the @ symbol represents any error message that is caused by a forbidden failed attempt, and the user will see the error message specified in die ().

Note that when connecting to multiple MySQL, you must specify the link ID for each connection, as follows:

 
  
  
  1. $ Link1 = @mysql_connect
    ("Server1", "User", "password")
  2. Or Die ("Could not connect to
    MySQL server! ");
  3. $ Link2 = @mysql_connect
    ("Server2", "User", "password")

  4. Connect to MySQL server! ");

PHP Mysql_pconnect () to establish and close database connections

 
  
  
  1. Resource Mysql_pconnect
    ([string hostname [:p ort]

Unlike mysql_connect (), the existing link is first found and is not created until it exists.
Note that you do not need to display a close connection (Mysql_close ()) because the connection will be placed in the pool, so it is called a persistent connection.

PHP mysql_close () to establish and close database connections

 
  
  
  1. Boolean mysql_close

Closing a connection is not necessary because it can be handled by MySQL garbage collection.
If link_id is not specified, the closest link is closed.


http://www.bkjia.com/PHPjc/446137.html www.bkjia.com true http://www.bkjia.com/PHPjc/446137.html techarticle PHP establishes and closes the database connection mysql_connect () resourcemysql_connect ([Stringhostname [:p ort][:/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.