Jump to content

Recommended Posts

i just created a new website for my local school
i want to create a databse which will contain roll number ,marksof variosu subjects & name of students
i created the database

but now when i am trying to create a php script to enter students details i am having prouble in connection :(

access denied for user 'abc'@'localhost'  todatabse 'abc_db'

 

what am i doing wrong ??
i think its because of user dont have proper privileges, how to give user privileges ?

 

Link to comment
https://forums.phpfreaks.com/topic/295537-having-problem-in-connection/
Share on other sites

yup they are on same server

i tried this script from w3school
<?php
$servername = "localhost";
$username = "uname";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>

& its Connected successfully :)

 

but i am having trouble in programming a script for entry of students details
can you guys help me in that ??

now when i am trying to create database
i am hacving problem

sctipt i m using
<?php
$servername = "localhost";
$username = "uname";
$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 school";
if ($conn->query($sql) === TRUE) {
    echo "Database created successfully";
} else {
    echo "Error creating database: " . $conn->error;
}

$conn->close();
?>

 

Error :
Error creating database: Access denied for user 'uname'@'localhost' to database 'school'
 

is phpmyadmin available? try going to http://localhost/phpmyadmin in your browser

I'd suggest creating the database through that and then just using PHP to deal with inserting and retrieving of rows.

 

 

i tried it

got this error

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

 

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

 

 

is phpmyadmin available? try going to http://localhost/phpmyadmin in your browser

I'd suggest creating the database through that and then just using PHP to deal with inserting and retrieving of rows.

 

are you able to log into phpmyadmin and see what users are created...?

otherwise what kind of machine are you on? windows? mac? linux? centos?

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.