tags:

views:

50

answers:

2

Hi, I am running mysql select queries 3500 times in a for loop and perform operations on the values returned by the queries in PHP. that process takes 16 seconds to execute for loop. any suggestion to reduce the execution time and improve the performance. thanks!

+2  A: 

Refactor your MySQL select so you only execute it once, not 3500 times. Tell us the queries in question, and we might be able to help you do it

Mark Baker
Actually i run the queries based on the time period. for example I am getting user logins number daily since 2001. thanks for your suggestions and give some suggestions to Refactor MYSQL
KMK
@KMK - Show us the SQL queries, and we might be able to refactor it for you - the most obvious solution for a time period query is with a group by - but without knowing the queries, there's not a great deal more that we can actually do to help.
Mark Baker
+5  A: 

Try to minimize the amount of queries, do you really need 3500 queries or can you select all rows in a single call?

If not, you can gain some performance by using prepared statements PDO gives you a easy to use interface for that.

http://dk2.php.net/manual/en/book.pdo.php

http://dk2.php.net/manual/en/pdo.prepare.php

Please paste some code if i need to be more specific :)

madsleejensen
Good solution - PDO prepare kind of precompiles the statement but with dynamic variables, so if you *do* have to run it 3500 times, it will still be far quicker.
adam
Actually I am running queries based on the time period. thanks for your suggestion.
KMK