Welcome Guest, Not a member yet? Register   Sign In
Create database if not exists?
#1

Is there a way to do "create database if not exists"?
DBFORGE only allows the `create_database` method, which does "create database", and if exists throws you off by displaying an error, not even an exception.
Reply
#2

PHP Code:
$dbName "YourName";

$sql "CREATE DATABASE IF NOT EXISTS $dbName";

$result $this->db->query($sql);

if (
$result)
{
 
   echo "Database $dbName Created.";
}
else
{
 
   echo "ERROR Creating Database $dbName";
}

exit(); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(10-17-2016, 10:50 AM)InsiteFX Wrote:
PHP Code:
$dbName "YourName";

$sql "CREATE DATABASE IF NOT EXISTS $dbName";

$result $this->db->query($sql);

if (
$result)
{
 
   echo "Database $dbName Created.";
}
else
{
 
   echo "ERROR Creating Database $dbName";
}

exit(); 

Thanks!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB