note 22163 deleted from function.mysql-list-tables by sp
| From: | sp@php.net | Date: | Sun, 29 Jan 2006 20:27:34 +0000 |
| Subject: | note 22163 deleted from function.mysql-list-tables by sp | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-102684@lists.php.net to get a copy of this message | ||
Note Submitter: the_php_guy at e-clecticity dot net
----
I was also surprised to find there's no function that lets you test for the existence of a
table.
There's a few problems with the solution offered above. For one thing, it's perfectly
possible (and legal) for a table to have no records - a condition that would not be caught by this
function.
Here's a better way to do it:
function mysql_table_exists($dbLink, $database, $tableName)
{
$tables = array();
$tablesResult = mysql_list_tables($database, $dbLink);
while ($row = mysql_fetch_row($tablesResult)) $tables[] = $row[0];
return(in_array($tableName, $tables));
}