I found other posts about this, but I could not solve my problem.
When I run a query by PHPMyAdmin, the query runs in 9 milliseconds
Showing records 0-24 (35 total Query took 0.0009 sec)
However, when you run the same query in the PHP server, the query takes 0.14 seconds.
$sql = "select cd_categoria, linha, slug, cd_categoria_site, qtd from ( SELECT cd_categoria, if (menu.cd_categoria_pai=0,menu.nm_categoria,concat((select nm_categoria from tb_st_category where cd_categoria = menu.cd_categoria_pai),';',nm_categoria)) as linha , if (menu.cd_categoria_pai=0,menu.nm_slug,concat((select nm_slug from tb_st_category where cd_categoria = menu.cd_categoria_pai),'/',menu.nm_slug)) as slug , cd_categoria as cd_categoria_site , 0 as qtd FROM tb_st_category menu where cd_categoria_pai = 0 ) as a order by linha";
$pagespeed = microtime_float();
$query = $mysqli->query($sql);
echo "Query Time:".number_format(microtime_float()-$pagespeed, 2, ',', '')."<br>";
How can I solve this problem? I need to reduce my site load time.
The same goes for the connection to the database. This taking 0.41 seconds. I think this time needs to be lowered
Testpage http://omenorpreco.com/teste.php
UPDATE:
According to https://stackoverflow.com/a/15293336/4275413 phpMyAdmin displays the query time that is reported from mysql itself, your script has all the overhead with wrappers, the mysqli library and stuff.