Hi, Is there is any option to create mysql data base automatically without using cpanel to create database, I use the following code but it does not create's Db on website. mysql_query("CREATE DATABASE fig",$connection); It creates DB in local but not in website?
I would recommend manually creation of databases. Then controlling them through php, and make sure the connection is right. You can use this script to connect to your database ( it is very simple but works ) PHP: <?php$database['host'] = 'host'; // change to your host$database['username'] = 'username'; // change to username$database['password'] = 'password'; // change to password$database['name'] = 'database'; // change to database name$db = mysql_connect($database['host'], $database['username'], $database['password']) OR die ('Cant connect to the database');mysql_select_db($database['name'], $db); // connection of database shouldn't be touched.?>
simple db creation is mysql_connect("localhost","root",""); mysql_select_db("databasename"); mysql_query("select * from tablename");
Huh? thats not how you create a database, its pretty much what i posted but way simpler and no connecting? That is how you select a database. Well not even, since you missed out some code.
Yes, iam able to connect to database and do manipulation after creation database on my site, i want to know is there is any option to create db using code without using cpanel
PHP: <?php$db = mysql_connect("host","user","pass");if (!$db) { die('Could not connect: ' . mysql_error()); } if (mysql_query("CREATE DATABASE my_db",$db)) { echo "Database created"; }else { echo "Error creating database: " . mysql_error(); } mysql_close($db);?> That's to create a database.
Finally my hosting company said database have to be created manually and they wont authorize to create DB using code. Thanks for your reply