By jarobinson1c on
This is a simple feature that I want to be able to use many times, detect if a record exists or not. I know how to do this in regular PHP and MySQL but not in Drupal's Database Abstraction Layer. There has been many times I wanted to do some PHP hacks but I'm trying to do things the Drupal way so future developers of my site don't have to learn Drupal and my hacks.
Comments
db_query() take a SQL
db_query() take a SQL statement so you can use that to run a SELECT query.
This is what I have...
This is what I have
My understanding is this is supposed to return 0 because the table is empty or the record dose not exist. It returns nothing.
This returns "Resource id #109", what the heck?
That's because the second one
That's because the second one is a mysql result. It doesn't become a value until you use db_fetch_array() or db_fetch_object() to extract the data from the resource.
Anyways, to find if something exists, you can use this:
$exists will be true if the record exists, false if it doesn't.
Contact me to contract me for D7 -> D10/11 migrations.
Thanks!
Thanks! It worked.