Page 2 of 2

Re: creating database and user

Posted: Thu Sep 24, 2009 4:11 pm
by rburgens
To echo Ollie Saunders more information is needed to help you:

a) who are you hosting with?
b) do you have (or can you get) SSH access to the server?
c) does the server have MySQL installed on it?
d) is the username and password for MySQL on the server accurate?

Also, I might add that the code you posted will only work correctly the first time it runs because you can only create a database once.

That is, running the query " create database $database_name" will create a database the first time, but every time you try it after that it will return an error because the database $database_name will already exist....

Re: creating database and user

Posted: Thu Sep 24, 2009 10:01 pm
by jashankoshal
no error is displayed...

Re: creating database and user

Posted: Thu Sep 24, 2009 10:06 pm
by jashankoshal
no i dont have SSH access to the server...

Re: creating database and user

Posted: Fri Sep 25, 2009 3:33 am
by myliquid
your code must be like this, see bold word, you lack your db connection at your query... i just add your connection...
<?php
$user=root;// give your phpmyadmin/cpanel username
$password="";// give your phpmyadmin/cpanel password
$database_name=jashan_db;// give your databse name
$database_user=jashan_koshal;// give your database user name
$user_password=12345;// give your password
$db=mysql_connect("localhost","$user","$password") or die("Not Working");

// code to create database
$database=" create database $database_name";
$result_db=mysql_query($database,$db);
if($result_db)
{
echo"<br>Database Created<br>";
}

// code to create database user
$dbuser="GRANT ALL PRIVILEGES ON $database_name.* TO $database_user@localhost IDENTIFIED BY '$user_password'";
$result_user=mysql_query($dbuser,$db);
if($result_user)
{
echo"<br>User Created</br>";
}
?>