Go4Expert

Go4Expert (http://www.go4expert.com/)
-   PHP (http://www.go4expert.com/forums/php/)
-   -   mysql db creation (http://www.go4expert.com/forums/mysql-db-creation-t15558/)

divinequran 20Dec2008 20:53

mysql db creation
 
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?

XenZy 30Dec2008 14:58

Re: mysql db creation
 
Quote:

Originally Posted by divinequran (Post 40437)
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 Code:

<?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.
?>


openwave 30Dec2008 19:16

Re: mysql db creation
 
simple db creation is


mysql_connect("localhost","root","");
mysql_select_db("databasename");
mysql_query("select * from tablename");

XenZy 30Dec2008 20:25

Re: mysql db creation
 
Quote:

Originally Posted by openwave (Post 40862)
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.

divinequran 4Jan2009 22:16

Re: mysql db creation
 
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

XenZy 7Jan2009 01:26

Re: mysql db creation
 
PHP Code:

<?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.

divinequran 16Jan2009 21:56

Re: mysql db creation
 
Finally my hosting company said database have to be created manually and they wont authorize to create DB using code. Thanks for your reply


All times are GMT +5.5. The time now is 09:56.