How to check if a mysql database already exists in php?

lamp, mysql, php

Solution

SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'DBName'

If you just need to know if a db exists so you won't get an error when you try to create it, simply use (From here):

CREATE DATABASE IF NOT EXISTS DBName;

Problem

Basically, I want to create a database, but I know there will be problem if you want to create a mysql database that already exists. So how can I check if it already exists in PHP? Here's the psuedo-code: ``` if (database exist) {do nothing} //if it doesn't exist else {create the database} ``` Now I already know how to create the database it self. That's easy for me, I just don't know how to check if one already exists.

Original source

Related problems