Query five data entries with three IDs in a table

Source: Internet
Author: User
Tags time 0
Test and query five data entries with three IDs in a table.

Test and query 5 pieces of data with three IDs in a table. wait for the code provided by the experts:

I wrote a single query combination faster than thinkphp because there are too many loops.

<? PHP

$ T1 = microtime ()
// Start time
$ DSN = "mysql: host = local host; dbname = Magazine ";

$ Db = new PDO ($ DSN, 'root', '', array (PDO: ATTR_PERSISTENT => true ));
$ DB-> setAttribute (PDO: ATTR_CASE, PDO: CASE_UPPER );
$ RS = $ decibel-> query ("SELECT * FROM TitleID where the content order passes ");
$ Array = array (40, 44, 45 );
$ AY = array (0, 0, 0 );
Arrival = array ();
And ($ ROW = $ RS-> get (PDO: FETCH_ASSOC )){
Foreach ($ array as $ key =>$ NUM ){
If ($ Row ['titleid'] = $ NUM ){
$ Arrives at [] = $ Row;
$ AY [$] + = 1;
If ($ AY [key] = 5 ){
Not set ($ array [key]);
}}}$ T2 = microtime in () // end time echo $ T2-T1 '-'; // Time 0.003067 RMB T11 = microtime in (); arrival = array (); $ reach [] = $ News> where ('titleid = 40')-> limit (5)-> Select (); $ arrive at [] = $ News> where ('titleid = 44')-> limit (5)-> Select () $ reach [] = $ News> where ('titleid = 45')-> limit (5)-> Select (); T22 = microtime (); echo $ T22-T11/time 0.00081301

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.