Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

how to fix this?

php mysql database error

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1 yhi

yhi

    CC Lurker

  • New Member
  • Pip
  • 3 posts

Posted 14 April 2015 - 10:31 AM

Error:



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

 

m using code from w3 school
 

<?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 ??


Edited by dargueta, 17 April 2015 - 02:57 PM.


#2 lespauled

lespauled

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1360 posts

Posted 14 April 2015 - 10:40 AM

It's telling you that your login information is wrong.  Change those values to the correct ones, and it will work.


My Blog: http://forum.codecal...699-blog-77241/
"Women and Music: I'm always amazed by other people's choices." - David Lee Roth

#3 yhi

yhi

    CC Lurker

  • New Member
  • Pip
  • 3 posts

Posted 14 April 2015 - 11:15 AM

It's telling you that your login information is wrong.  Change those values to the correct ones, and it will work.

lol

the script i am using on my website have corrent value 
otherwise will get  Connection failed error 
 



#4 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts

Posted 14 April 2015 - 12:06 PM

Connection failed is if you enter the wrong server. You entered the wrong username/password for the database.


Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#5 yhi

yhi

    CC Lurker

  • New Member
  • Pip
  • 3 posts

Posted 14 April 2015 - 12:41 PM

Connection failed is if you enter the wrong server. You entered the wrong username/password for the database.

nope its correct

i created a new user for db & run this code

<?php
$servername = "localhost";
$username = "username";
$password = "password";

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

// Create database
$sql = "CREATE DATABASE myDB";
if ($conn->query($sql) === TRUE) {
    echo "Database created successfully";
} else {
    echo "Error creating database: " . $conn->error;
}

$conn->close();
?>

output is same

Error creating database: Access denied for user 'bhseuser'@'localhost' to database 'myDB'


Edited by dargueta, 17 April 2015 - 02:57 PM.


#6 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts

Posted 17 April 2015 - 02:58 PM

The password might be right, but does the user bhseuser have create permissions?


sudo rm -rf / && echo $'Sanitize your inputs!'