PDA

View Full Version : checking for existance of a table.


turnipofdoom
06-21-2007, 09:29 PM
In a mod I am writing I use this query:


SELECT count(*) cnt
FROM information_schema.tables
WHERE table_schema = '$db_tmp_name'
AND table_name = '".TABLE_PREFIX."mytable'";


db_tmp_name is set properly before the query, it works fine on my dev machine, however I asked someone here to beta test it, and he got table doesnt exist error. So does someone have a fool proof method to check weather a table exists for mysql4 ?

Paul M
06-21-2007, 09:58 PM
The query SHOW TABLES will list all the tables in a database - load them into an array and then use in_array() to check if a table exists.