Pregunta

I don't understand why MYSQL query takes more time in PHP script but takes less time in phpMyAdmin

Query :

SELECT `id`, `title`, `slug`, `price`, `image`, `seller` FROM (`products`) WHERE `price` >= '0' AND `price` <= '2000' AND `cp_price` != '0' AND `category` LIKE '%,2,%' ORDER BY `id` DESC LIMIT 20, 20

phpMyAdmin time : 0.00 sec

php script time : around 8-12 sec

¿Fue útil?

Solución

Make a page and connect the page to DB. On that page keep nothing but only your query and then run the page ad see. Your query will not take much time. The issue is somewhere else.

Otros consejos

Please try using persistent connection to MySQL DB: http://www.php.net/manual/en/features.persistent-connections.php - they pay off because you do not have to setup a connection first.

You may also try using a profiler to find out where the bottleneck is. For instance: http://www.php-trivandrum.org/open-php-myprofiler/

Install this => PhP Debug Toolbar, setup database connection and then you will get the profiling details about timing in the database connection, maybe the time that the server took to serve the page its not mysql's fault

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top