Posted on

CREATING MYSQL DATABASE DYNAMICALLY USING CODE

All About Technology

I  have come across a project in which i have to create database and its associated user dynamically.

Let us store our cpanel settings in variable

$box_num = 000;
$cPanel_user = ‘XXXXXXX’ ;  // cpanel username
$cPanel_pass = urlencode(‘YYYYYYYY’); // cpanel password

//Database to create

$userDb = ‘test’;
$db = $cPanel_user.’_’. $userDb; //  e.g XXXXXXX_test

$db_user = $cPanel_user.’_myuser’;  // username to be created
$db_pass = ‘mypass’;  // password to be created

//Permission must stay in uppercase. This will give the user full permissions. Remove the ones that you don’t want.

$permissions = array(‘SELECT’ => ‘SELECT’, ‘INSERT’ => ‘INSERT’, ‘UPDATE’ => ‘UPDATE’, ‘DELETE’ => ‘DELETE’, ‘CREATE’ => ‘CREATE’, ‘ALTER’ => ‘ALTER’, ‘DROP’ => ‘DROP’, ‘LOCKTABLES’ => ‘LOCK’,                 ‘INDEX’ => ‘INDEX’, ‘REFERENCES’ => ‘REFERENCES’, ‘CREATETEMPORARYTABLES’ => ‘TEMPORARY’,
‘CREATEROUTINE’ => ‘CREATEROUTINE’);

Now let us define the host path, replace domain name with your domain name

$host = ‘http://’ . $cPanel_user . ‘:’ …

View original post 136 more words

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s