How in PHP would I check for a condition if a MySQL TABLE already exists and it shouldn't and need to abort but with a message that's meaningful? Thanks!
3 Answers
Try creating the table. You should get an error: 1050 "table already exists".
Or you can try this: https://stackoverflow.com/a/1525801/2427840
Comments
mysql_ - functions are deprecated as of PHP 5.5.0. You should use MySQLi or PDO.
To check if a table exists you can use this query:
SELECT COUNT(*)
FROM information_schema.tables
WHERE table_schema = '[database-name]'
AND table_name = '[table-name]';
1 Comment
PLPeeters
+1 for using the
information_schema and specifying mysql_ functions are deprecated.