MySQL check if a table exists without throwing an exception?

I don't know the PDO syntax for it, but this seems pretty straight-forward: $result = mysql_query("SHOW TABLES LIKE 'myTable'"); $tableExists = mysql_num_rows($result) > 0.

Thanks, totally forgot that SHOW TABLES LIKE could be limited to one exact table only – clops Oct 6 '09 at 14:08.

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: electrictoolbox.com/check-if-mysql-table....

Oh! Didn't think of that. Let me check if it works as expected!

– clops Oct 6 '09 at 14:04 maybe I'm missing something, but why would you use this method over SHOW TABLES? – nickf Oct 6 '09 at 14:06 @nickf It's part of the ansi standard, so it's portable between different rdbms'es. – troelskn Oct 6 '09 at 14:15 @nickf: It also works on databases other than MySQL.

This includes PostgreSQL and SQL Server as far as I can tell. – Powerlord Oct 6 '09 at 14:16 wondering if this is a security exploit you can query information from databases you aren't connected to... – Talvi Watia 04 may8 at 4:41.

What is the best way to check if a table exists in MySQL (preferably via PDO in PHP) without throwing an exception. I do not feel like parsing the results of "SHOW TABLES LIKE" et cetera. There must be some sort of boolean query?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions