PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Dec 16, 2018 9:03 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: how to fix this??
PostPosted: Tue Apr 14, 2015 1:30 pm 
Offline
Forum Newbie

Joined: Tue Apr 14, 2015 1:19 pm
Posts: 2
Error:



Connection failed: Access denied for user 'uname'@'localhost' to database 'test_db'

m using code from w3 school

Syntax: [ Download ] [ Hide ]
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// sql to create table
$sql = "CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)"
;

if ($conn->query($sql) === TRUE) {
    echo "Table MyGuests created successfully";
} else {
    echo "Error creating table: " . $conn->error;
}

$conn->close();
?>






i think i have to give privilege to user

how to do it ??


Top
 Profile  
 
 Post subject: Re: how to fix this??
PostPosted: Tue Apr 14, 2015 1:40 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
Either your username is wrong, the password is wrong, or the user doesn't have access.

Run this query in some database thing, like phpMyAdmin, and post the result.
Code:
SHOW GRANTS FOR uname@localhost


Top
 Profile  
 
 Post subject: Re: how to fix this??
PostPosted: Tue Apr 14, 2015 1:54 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6424
Location: Montreal, Canada
yhi wrote:
m using code from w3 school

PHP: The Right Way

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
 Post subject: Re: how to fix this??
PostPosted: Tue Apr 14, 2015 2:51 pm 
Offline
Forum Newbie

Joined: Tue Apr 14, 2015 1:19 pm
Posts: 2
requinix wrote:
Code:
SHOW GRANTS FOR uname@localhost



query not workng :/


Top
 Profile  
 
 Post subject: Re: how to fix this??
PostPosted: Tue Apr 14, 2015 3:25 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
Not working how?

Did you put the right username in there? Your error message said "uname" but your code, no doubt edited before you posted it, says "username".


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group