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

Link to comment
Share on other sites

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
Share on other sites

I mean is there a way to just ask the DB if the record exists or not, and the DB will just see if it exists and tell PHP if it exists, without actually reading the data in it (except for searching)?

Link to comment
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.

Link to comment
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
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.