RE: [PHP] Finding out if a table exists

From: Date: Tue, 21 Jan 2003 18:21:46 +0000
Subject: RE: [PHP] Finding out if a table exists
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-132478@lists.php.net to get a copy of this message
On 21-Jan-2003 Mako Shark wrote: > Is there a way of finding if a table exists with only > one command in MySQL? I've looked through the MySQL > functions, and the closest I've gotten to what I need > is mysql_list_tables or mysql_tablename (I'll have to > check into these a little more), but I was hopefully > looking for something that returns a boolean value, > and to be able to use it like: > > if(mysql_table_exists("tablename")) { > ... > } > > Any ideas, short of creating my own function? > Create your own, or borrow mine: function tableexists($tbl) { $res = @mysql_query("SELECT 1 FROM $tbl LIMIT 1"); return ($res ? true : false); } Regards, -- Don Read dread@texas.net -- "Beer is proof that God loves us and wants us to be happy."

« previous php.general (#132478) next »