What's more optimized, from the both examples bellow? Example 1: $query=mysql_query("SELECT * FROM `DB` WHERE id>20 LIMIT 10;"); $query=mysql_query("SELECT * FROM `table2` WHERE id>20 LIMIT 10;"); $query=mysql_query("SELECT * FROM `db_table WHERE id>0 LIMIT 30;"); PHP: Example 2: $query=mysql_query("SELECT * FROM `DB` WHERE id>20 LIMIT 10; SELECT * FROM `table2` WHERE id>20 LIMIT 10; SELECT * FROM `db_table WHERE id>0 LIMIT 30;"); PHP:
I never did that from example 2, but I guess cause it works, since I saw in phpmyadmin, that it can execute multiple sql commands by adding ; after each query.
Optimization wise it makes no difference. However, following standard coding guidelines, the first is more user-friendlier and easier to operate with. If you want to optimize, instead of selecting *, just select the fields you are only going to use. Also use mysql_fetch_assoc,mysql_fetch_row instead of mysql_fetch_array. Peace,
in case if I need all the db details, I'll use *, but in those cases, is any difference? Who's faster, the example 1, or example 2. Or same speed?
No one can ever tell you what is faster. Some queries might be fast on one computer, while slow on the other. Use something like this to get real time data to test your code: http://www.wallpaperama.com/forums/php-code-snippet-page-load-speed-test-generated-script-t79.html Peace,
are you sure example 2 actually works? I thought it was not possible because of the sql injection risks associated.
I don't think #2 works. Because return result will be #Resource; #2 will return 3 Resource; when how will(should) you do to get arrays from these #Resource?