Jump to content

Fast select


Azu

Recommended Posts

Can someone please tell me if there is a faster way then

if(mysql_result(timed_query("select count(*) from table where info='blah'",$DB),0))

to just see if a row exists that matches the where? I don't actually want to retrieve any data from it, just see if it exists..

 

You will have to retrieve data from the DB server. How would the scripting language know if the record exists or not. You could simply return a 1 or 0 instead of columns but yes you would have to return data.

 

Link to comment
https://forums.phpfreaks.com/topic/44460-fast-select/#findComment-222597
Share on other sites

query:

 

SELECT id
FROM table
WHERE id = $id
LIMIT 0,1

 

php:

 

if(mysql_num_rows($result) > 0)
  do something.

 

As stated above you have to return "something".  Just make sure that something is as small as possible.  Also make sure you have indexed your 'id' field.

 

You could choose this technique too.

Again you will have to execute the query and the result will be returned to the scripting language.

 

Link to comment
https://forums.phpfreaks.com/topic/44460-fast-select/#findComment-222945
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.