How does php connect to multiple databases at the same time?

Source: Internet
Author: User

The following is a function that can be used to connect different tables in multiple databases. You can add it to your favorites. It is more practical and useful for tests.

Function mysql_connect ($ region, $ db, $ table, $ where = '1', $ limit = '10') {$ conn = mysql_connect ('localhost', 'like ', 'admin', true) or mysql_error (); mysql_select_db ($ db, $ conn); mysql_query ("set names utf8 "); // It must be consistent with the form data character if ($ rows = 'select') {$ query = "select * from '$ table' where ". $ where. "limit ". $ limit; $ res = mysql_query ($ query, $ conn) or die ("failed to get data"); $ arr = array (); while ($ row = mysql_fetch_row ($ res) {$ arr [] = $ row;} mysql_close ($ conn); return $ arr ;}}


The query operation is performed by default. You can modify this code as required !, Is the code under the $ signature operator.

For example, if I want to query the shop data table in the database named test with the id ranging from 10 to 12, then I can call it like below.

Mysql_select ('select', 'test', 'shop ', 'Id> = 10 and id <= 12 ');



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.