girish.kc Posted February 4, 2011 Share Posted February 4, 2011 Hi, I am creating a temporary table. I need to check if the table already exists or not. If exists, I have to use the existing data else have to create a new temporary table. I can use 'Create If Not Exists'. How practical is this query? any issues with the performance? If the table exists it will be a huge data, I don't want to loose that data because recreating is an un-necessary load on the database. Link to comment https://forums.phpfreaks.com/topic/226662-how-to-check-the-mysql-table-exists-or-not/ Share on other sites More sharing options...
Roman Fedorov Posted February 4, 2011 Share Posted February 4, 2011 Hi, <? function table_exists ($table, $db) { $tables = mysql_list_tables ($db); while (list ($temp) = mysql_fetch_array ($tables)) { if ($temp == $table) { return TRUE; } } return FALSE; } /** How to use it **/ if (table_exists(test_table, my_database)) { echo"Yes the table is there."; } ?> Link to comment https://forums.phpfreaks.com/topic/226662-how-to-check-the-mysql-table-exists-or-not/#findComment-1169775 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.