I need a simple code to check if a record exists in a db table. I found this code which does what I want though db_result no longer exists in D7.$exists = db_result(db_query('SELECT 1 FROM {artistfield} WHERE uid = %d', $user->uid));
How would I write this statement in D7?
Comments
Just getting used to D7
Just getting used to D7 myself, does something like the below work?
Log in or register to post comments
Yeah I don't think there's an
Yeah I don't think there's an equivalent of db_result(). That's the closest I've found, so note that you will get an object, which means you need to check it with
$result->1
or similar instead of just$result
.Log in or register to post comments
Think I got it
How about something like this...
Got that from here..
http://api.drupal.org/api/drupal/includes--database.pgsql.inc/function/d...
Log in or register to post comments
Oooooh now I think I remember
Oooooh now I think I remember seeing that before too. Thanks.
Log in or register to post comments
That was just what I was
That was just what I was looking for! All works great now!
Thanks guys!!!
Log in or register to post comments
Alternative way to write db_result
If you are working in a migration project from d6 to d7 and if there are multiple occurrence of db_result in your custom module you can simply write the below function in any of your custom module without changing the same.