Jump to content

determining if table has no record?


coder9

Recommended Posts

I'm not going to argue, though I don't really see one being more efficient than the other. The both require the execution of one query and both use two function calls. Really wouldn't be much in it.

Link to comment
Share on other sites

I was too lazy to consult the php source on this one, but if I recall, mysql_num_rows() would actually be loading a new string/array engine to actually count the number of records, but I could be woefully wrong (I guess it would do this in mysql too, but as I said, I checked neither source). I guess the only way to test it would be a speed test of each script.

Link to comment
Share on other sites

Count(*) only ever returns a single field no matter how many recs are in the file. If there were 1000 recs in the file, SELECT foo pulls a 1000 foos down just so you can call num_rows().

 

"SELECT COUNT(*) FROM tbl" is optimised so it doesn't even need to read the table, it just looks it up in its internal tables.

Link to comment
Share on other sites

Count(*) only ever returns a single field no matter how many recs are in the file. If there were 1000 recs in the file, SELECT foo pulls a 1000 foos down just so you can call num_rows().

 

"SELECT COUNT(*) FROM tbl" is optimised so it doesn't even need to read the table, it just looks it up in its internal tables.

 

That makes sense, you win :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.