Faster tableExists function
Date: 02/07/07
(PHP Community) Keywords: mysql, sql
Pre-question: what's a good method for displaying a script in livejournal?
Real question:
Below the cut is a very quick function I wrote up to query for the existence of a table in MySQL. I want to cut it down even further and I was thinking the logic :
start table exists
query `SHOW TABLES LIKE 'myTable';
if result && result num_rows > 0 then table exists?
return true
else
return false
end table exists
would be faster because it wouldn't loop. My thought is, the only way the query could return true(1+ results) is if it matched that table exactly (lack of %'s in the query expression). Anyone disagree?
Source: http://community.livejournal.com/php/539308.html