Tuesday, February 23, 2010

PHP, MySql - Check table existance | table exist

This function is to check whether the required table exist or not

function TableExists($tablename, $db) {

// Get a list of tables contained within the database.
$result = mysql_list_tables($db);
$rcount = mysql_num_rows($result);

// Check each in list for a match.
for ($i=0;$i<$rcount;$i++) {
if (mysql_tablename($result, $i)==$tablename) return true;
return false;

No comments: