Jump to content

Access Denied while creating Database.


Nxt

Recommended Posts

Hey!

 

Okay, so i've been looking up some tutorials on PHP and MySQL. I feel that downloading a pre-made script limits on your creativity and handling procedures. Plus, you get that damn copyright info that will indicate to other users on your site that you never made that sciprt. :(

 

So, I write up a test script to

1) Connect to Mysql server.

2) Create a database.

3) Insert a new table inside the database.

 

Here's the code:

 

<?php

 

$sql = mysql_connect('localhost','nxtwaren_God',"mypassword") or die("Couldn't connect to mysql server.".mysql.error());

 

?>

 

That's in the sqlconnect.php

 

now here's the createdb.php :

 

?php

 

include 'sqlconnect.php';

// create database

mysql_query("CREATE DATABASE nxtwaren_blogsystem") or die(mysql_error());

 

// Select Database

 

mysql_select_db("nxtwaren_blogsystems",$sql) or die(mysql_error());

 

// Create a new table!

mysql_query("CREATE TABLE users (

                    username varchar(30),

                    age tinyint(2),

                    posts mediumint(9)

                    )

                ") or die(mysql_error());

echo("Database was created successfully!");

 

// Lets say we got the information via a POST form

$username = 'Bob';

$age = 40;

$posts = 5000;

 

mysql_query("INSERT INTO users (username, age, posts) VALUES ('".$username."', ".$age.", ".$posts."") or die(mysql_error());

echo ("Successfully inserted data into new table!");

 

 

?>

 

 

So the result when I run the script createdb.php

 

is:

 

Access denied for user 'nxtwaren_God'@'localhost' to database 'nxtwaren_blogsystems'

 

Any help-would be really appreciated! Thanks!

 

-NxT

Link to comment
Share on other sites

There could be several reasons for this! :-\

If I get error messages that I can`t pinpoint, I Google the error message to see if I didn`t miss anything and to better determine what I did wrong! ;D

 

make sure the database settings in config.php are correct or

 

GRANT ALL PRIVILEGES ON database_name TO user@host IDENTIFIED BY 'password';

FLUSH PRIVILEGES;

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.