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
https://forums.phpfreaks.com/topic/125682-access-denied-while-creating-database/
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;

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.