Jump to content

Fastest Way


jaymc

Recommended Posts

$connection is the variable I use as a handle for the database connection

e.g.

       $connection = mysql_connect("localhost","username","password") or die ("Could not connect: " . mysql_error());
       mysql_select_db("databasename",$connection) or die ("Could not select db: " . mysql_error());

 

I don't know if COUNT is quicker, but the easy way to find out is create a large table and do some timings.

 

It's certainly more efficient in Oracle.

Link to comment
https://forums.phpfreaks.com/topic/48524-fastest-way/#findComment-237465
Share on other sites

Instead of

 

$querystring = "SELECT COUNT(*) FROM table WHERE username = 'fred'";

 

You may prefer to use

 

$querystring = "SELECT COUNT(id) FROM table WHERE username = 'fred'";

 

Assuming id is a primary key. If you want to go farther, add an index on username. This would be optimal, I believe.

 

The difference isn't super profound right now (~0.0007ms on 300 records, ~0.0021ms on 3,000 records) but will be more appearant with a lot of records.

Link to comment
https://forums.phpfreaks.com/topic/48524-fastest-way/#findComment-238418
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.