How to connect multiple MySQL databases in PHP _php tutorial

Source: Internet
Author: User

How to connect multiple MySQL databases in PHP


Sometimes, we may be in a PHP project to connect multiple MySQL database, it is necessary to write multiple mysql_connect and mysql_select_db, but some children's shoes found written to write all in fact always call the last database.

In fact, the correct wording is:

Database 1

$conn 1 = mysql_connect (' localhost:3306 ', ' root ', ' 111111 ', true);

mysql_select_db (' db1 ', $conn 1);

mysql_query (' Set names UTF8 ');

Database 2

$conn 2 = mysql_connect (' localhost:3306 ', ' root ', ' 222222 ', true);

mysql_select_db (' DB2 ', $conn 2);

mysql_query (' Set names UTF8 ');

The principle is that the Mysql_connect function sets the "New_link" parameter to true to force the use of the new connection.

mysql_connect function

Resource mysql_connect ([string server [, String username [, string password [, bool new_link [, int client_flags]]])

http://www.bkjia.com/PHPjc/834968.html www.bkjia.com true http://www.bkjia.com/PHPjc/834968.html techarticle ways to connect multiple MySQL databases in PHP Sometimes, we might connect multiple MySQL databases in a PHP project, write multiple mysql_connect and mysql_select_db, but some kids ...

  • 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.