I want my php code to check whether a certain DB exists, by means of running some sql query andd parsing the result.
What would be a nice way to do it?
Thanks
Gidi
Run SHOW DATABASES and loop over the results with PHP to check for the existence.
If it were only one database, you could also add a condition to the SQL query directly and simply check if it returned a result or not with PHP. This would avoid the loop.
LIKE condition. See middaparka's example or the docs.As a simple solution, you could just use:
SHOW DATABASES LIKE <YOUR DB NAME>;
See the SHOW DATABASES Syntax manual page for more information.
I suppose you could connect to your server, and issue a show databases statement.
It'll get you a list of all database that you can access, on your server.
If it doesn't exist, that function will most likely fail -- and return false.