Help - Search - Members - Calendar
Full Version: Connecting To Mysql Using Php
BleepingComputer.com > Software > Programming
   
brennr26
Hey!

I'm trying to connect to a mySql database using PHP but I am being denied access to the database.

"--
Warning: mySql_connect(): Access denied for user: 'robbie@localhost' (Using password: YES) in C:\Program Files\Apache Group\Apache2\htdocs\hello.php on line 6
Error connecting to mySql
--"

Here is my PHP
<?php
$dbhost = 'localhost';
$dbuser = 'robbie';
$dbpass = 'password';

$conn = mySql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mySql');

$dbname = 'petstore';
mySql_select_db($dbname);
?>


I created the mySql account like this...
"--
mySql> INSERT INTO user (host, user, password, select_priv, insert_priv, update_priv, delete_priv, create_priv, drop_priv) VALUES ('localhost', 'robbie', 'password', 'Y', 'Y', 'Y', 'Y', 'Y','Y');
Query OK, 1 row affected (0.00 sec)

mySql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
--"

Does anybody have an idea what is causing the error?

I know that without the FLUSH PRIVILEGES command the user will not be able to connect to the database and after the FLUSH PRIVILEGES command above it says "0 rows affected"!
Does this mean that FLUSH PRIVILEGES command did not take effect?

Thank you for reading!
Grinler
Using mysqladmin you can see if the users exists by doing this:

use mysql;
select * from users


If that row shows the nthe user exists. Also I think you need to give it usage permissions. I manage mysql through phpmyadmin which makes this MUCH easier.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.