Determining Whether an Item Exists in a Database

Before reading or setting an element in a database, it is sometimes useful to know whether the element exists. You can do this with the dba_exists() function, which requires the name of the element for which you are testing and a valid DBA resource. It returns true if the element exists:

if ( dba_exists("Tricorder", $dbh ) )
  print dba_fetch( "Tricorder", $dbh );

Get Sams Teach Yourself PHP in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.