Determine if table exists, if it's empty, without errors...?
Posted: Thu Jul 17, 2008 6:26 pm
It seems as though I've got the MySQL down but not the PHP as far as trying to determine if a table exists and then checking to see if it's empty.
With the SHOW TABLES MySQL query I ended up pulling an array of columns/rows of tables however only in PhpMyAdmin could I see the full list where as in the browser it appeared as though I could not get the second row with the second table's name...so in my mind last night I was unable to access a subarray in some sort of sense...?
Secondly once I select a table (presuming it exists) I want to determine if it's empty of not. I read online that you want to check for the number of columns so while I have the idea/code for MySQL I'm coming up short in regards to PHP...
So I want to determine if a table exists without spawning any error messages.
Then (if the table exists) {I want to determine if that table is empty}.
Suggestions please?
With the SHOW TABLES MySQL query I ended up pulling an array of columns/rows of tables however only in PhpMyAdmin could I see the full list where as in the browser it appeared as though I could not get the second row with the second table's name...so in my mind last night I was unable to access a subarray in some sort of sense...?
Code: Select all
$check1 = mysql_query("SHOW TABLES FROM $db_name");Code: Select all
$result = mysql_query("SELECT count(*) FROM $db_name");
//$row = mysql_fetch_row($result);
echo $result;Then (if the table exists) {I want to determine if that table is empty}.
Suggestions please?