creating database and user

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

rburgens
Forum Newbie
Posts: 8
Joined: Thu Sep 24, 2009 12:57 pm

Re: creating database and user

Post 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....
jashankoshal
Forum Newbie
Posts: 7
Joined: Wed Sep 23, 2009 10:50 pm

Re: creating database and user

Post by jashankoshal »

no error is displayed...
jashankoshal
Forum Newbie
Posts: 7
Joined: Wed Sep 23, 2009 10:50 pm

Re: creating database and user

Post by jashankoshal »

no i dont have SSH access to the server...
myliquid
Forum Newbie
Posts: 1
Joined: Fri Sep 25, 2009 3:30 am

Re: creating database and user

Post 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>";
}
?>
Post Reply