creating database and user
Moderator: General Moderators
-
jashankoshal
- Forum Newbie
- Posts: 7
- Joined: Wed Sep 23, 2009 10:50 pm
creating database and user
hello,
i want to create database,user,tables and insert rows using the code.
do not want to use the phpmyadmin and cpanel.
filename.php should do everything.
i have written the code and it is working in WAMP but not working in web server...
can anyone figure it out plz..
thnks.
i want to create database,user,tables and insert rows using the code.
do not want to use the phpmyadmin and cpanel.
filename.php should do everything.
i have written the code and it is working in WAMP but not working in web server...
can anyone figure it out plz..
thnks.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Re: creating database and user
So, um, what happens?
Make sure error reporting is set to E_ALL and display_errors is on and tell us what error you are getting. If you're using the error suppression operator anywhere, stop.
Make sure error reporting is set to E_ALL and display_errors is on and tell us what error you are getting. If you're using the error suppression operator anywhere, stop.
Re: creating database and user
Usually that happens because the connection string needs to change in order to connect to the server instead of your WAMP box. Check the host, port, dbname, and password and make sure they are valid on the server.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Re: creating database and user
Are you failing to make a database connection then? Is that a hunch or do you have an error telling you that's the problem?
Re: creating database and user
That is my guess based on similar issues I've had before. But if the error reporting is turned on like you mentioned that would tell us for sure if that's the case.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Re: creating database and user
Yeah, you must have evidence.
-
jashankoshal
- Forum Newbie
- Posts: 7
- Joined: Wed Sep 23, 2009 10:50 pm
Re: creating database and user
thankyou guys for reply..
here is the code...
can u help me in changing it...
<?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);
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);
if($result_user)
{
echo"<br>User Created</br>";
}
?>
here is the code...
can u help me in changing it...
<?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);
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);
if($result_user)
{
echo"<br>User Created</br>";
}
?>
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Re: creating database and user
Please surround any code with [syntax=php]tags when posting.[/syntax]
Re: creating database and user
I imagine the database user you're connecting with online doesn't have the CREATE or GRANT privileges in MySQL.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Re: creating database and user
A few stylistic issues:
Strings should be quoted with either a single (') or double quote ("); so:becomes:
Any comment that tells you something that your code already does is redundant, and redundancy is a programmer's enemy. For example:should become:
Finally, performing string interpolation around a single variable with double quotes is redundant. Code like this:should be changed to something more like this:
To solve your problem you might want to download a graphical MySQL client and attempt to connect and perform the GRANT operation with that. If you can't connect with that, you won't be able to connect with PHP, which would make it a configuration issue. Any other errors in your PHP might be found by setting your error_reporting level to E_ALL, which I strongly recommend.
Strings should be quoted with either a single (') or double quote ("); so:
Code: Select all
$user=root;Code: Select all
$user = 'root';Code: Select all
$database_name=jashan_db;// give your databse nameCode: Select all
$database_name = 'jashan_db';Code: Select all
$db=mysql_connect("localhost","$user","$password")Code: Select all
$db = mysql_connect('localhost', $user, $password)-
jashankoshal
- Forum Newbie
- Posts: 7
- Joined: Wed Sep 23, 2009 10:50 pm
Re: creating database and user
thanks again..
can plz tell me how to make "error_reporting level to E_ALL"???
can plz tell me how to make "error_reporting level to E_ALL"???
-
jashankoshal
- Forum Newbie
- Posts: 7
- Joined: Wed Sep 23, 2009 10:50 pm
Re: creating database and user
its not working...
i donno what to do...
my code is working on WAMP...but it is not working on WEB SERVER.
i donno what to do...
my code is working on WAMP...but it is not working on WEB SERVER.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Re: creating database and user
Oh, I missed an important point here. What kind of hosting do you have? Unless you have SSH access to the server there's probably no way you can actually write any PHP that will have permission to create a database table and issue a grant query.
Does your server not come with facilities for creating tables etc. Contact your host's support / view the instructional literature.
Also, please don't say "not working". These two words lack all information; what isn't working? What happens when you try?
Does your server not come with facilities for creating tables etc. Contact your host's support / view the instructional literature.
Also, please don't say "not working". These two words lack all information; what isn't working? What happens when you try?
Re: creating database and user
Amen to that!Also, please don't say "not working". These two words lack all information; what isn't working? What happens when you try?