MySQL check if a table exists without throwing an exception
If you're using MySQL 5.0 and later, you could try:
SELECT COUNT(*)FROM information_schema.tables WHERE table_schema = '[database name]' AND table_name = '[table name]';
Any results indicate the table exists.
From: http://www.electrictoolbox.com/check-if-mysql-table-exists/
Using mysqli i've created following function. Asuming you have an mysqli instance called $con.
function table_exist($table){ global $con; $table = $con->real_escape_string($table); $sql = "show tables like '".$table."'"; $res = $con->query($sql); return ($res->num_rows > 0);}
Hope it helps.
Warning: as sugested by @jcaron this function could be vulnerable to sqlinjection attacs, so make sure your $table
var is clean or even better use parameterised queries.