Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Firehawk777 on
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?
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
.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...
Oooooh now I think I remember
Oooooh now I think I remember seeing that before too. Thanks.
That was just what I was
That was just what I was looking for! All works great now!
Thanks guys!!!
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.