yhi Posted April 14, 2015 Share Posted April 14, 2015 i just created a new website for my local schooli want to create a databse which will contain roll number ,marksof variosu subjects & name of studentsi 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/295537-having-problem-in-connection/ Share on other sites More sharing options...
joel24 Posted April 14, 2015 Share Posted April 14, 2015 are the database and php code both on the same server/machine - i.e. your localhost? Are you sending over a password when you try to connect? go to http://localhost/phpmyadmin and have a look at the user and ensure it's setup correctly. Quote Link to comment https://forums.phpfreaks.com/topic/295537-having-problem-in-connection/#findComment-1509005 Share on other sites More sharing options...
yhi Posted April 14, 2015 Author Share Posted April 14, 2015 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 connectionif ($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 detailscan you guys help me in that ?? Quote Link to comment https://forums.phpfreaks.com/topic/295537-having-problem-in-connection/#findComment-1509008 Share on other sites More sharing options...
yhi Posted April 14, 2015 Author Share Posted April 14, 2015 now when i am trying to create databasei am hacving problemsctipt i m using<?php$servername = "localhost";$username = "uname";$password = "password";// Create connection$conn = new mysqli($servername, $username, $password);// Check connectionif ($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' Quote Link to comment https://forums.phpfreaks.com/topic/295537-having-problem-in-connection/#findComment-1509009 Share on other sites More sharing options...
joel24 Posted April 14, 2015 Share Posted April 14, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/295537-having-problem-in-connection/#findComment-1509014 Share on other sites More sharing options...
yhi Posted April 14, 2015 Author Share Posted April 14, 2015 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 ?? Quote Link to comment https://forums.phpfreaks.com/topic/295537-having-problem-in-connection/#findComment-1509034 Share on other sites More sharing options...
joel24 Posted April 14, 2015 Share Posted April 14, 2015 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? Quote Link to comment https://forums.phpfreaks.com/topic/295537-having-problem-in-connection/#findComment-1509082 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.