For two tables, it is usually a direct association or a two-time Association.

Source: Internet
Author: User
For two tables, is it generally a direct association or two queries, such as a user table or a user education table {code? Isn't it possible to directly associate the database? Is it possible to allow php to join the database more than once? For other tables, such as busy businesses or services... for two tables, it is usually directly associated or found twice before association, such as user tables and user education tables.

$user_ids = query(select id from users);$background = query('select * from background where uid in '.implode(',',$user_ids));

Do you need this? Isn't it possible to directly associate the database? Is it possible to allow php to join the database more than once?
For other tables, such as busy businesses or busy businesses, do you have to treat them separately?

Reply content:

For two tables, whether to directly associate the table or perform association after two queries, such as the user table and user education table

$user_ids = query(select id from users);$background = query('select * from background where uid in '.implode(',',$user_ids));

Do you need this? Isn't it possible to directly associate the database? Is it possible to allow php to join the database more than once?
For other tables, such as busy businesses or busy businesses, do you have to treat them separately?

Not tested. However:

  1. The database is easy, and the task of your PHP program is heavier. After all, databases that query tables are more professional.
  2. Added Network data transmission.
  3. If you get a large number of data entries, Your PHP needs to generate a large string and transmit it to the database. Then the database has to spend more time Parsing Memory and CPU. If your id is complex, you may make a mistake.
  4. If the data changes between two queries result in inconsistent results with the query results of one join table, will this affect your business logic?

If the access volume is large enough, this can indeed reduce the pressure on the database, but this will increase the complexity and it is not recommended to optimize it too early.

Manage SQL resources and provide placeholders as configured in the configuration file;
Design a parser module to obtain parameters and replace placeholders;
Execute the query and return the results. You can also input the type to perform reflection on the query results;

The combined query is better. After all, I/O operations are performed separately.

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.