Forum Moderators: coopster

Message Too Old, No Replies

Help.

Database error: Access denied for user:

         

web_young

4:34 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



I'm 'trying' to set up my first apache, php, mysql database and I'm getting this error.

Database error: Access denied for user: '@localhost' to database 'testdatabase'

Does anyone know how I can fix it?

Here's the code for my PHP page:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>MySQL Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<h3> Press RELOAD to add a record to the MySQL database:</h3>
<?
//establish user connection
mysql_connect("localhost");
//open up database
mysql_create_db("testdatabase");
mysql_select_db("testdatabase") or die ('Database error: ' . mysql_error());
//create table
mysql_query("CREATE TABLE newone(firstName VARCHAR(25),lastName VARCHAR(25))");
mysql_query ("INSERT INTO newone (firstName, lastName) VALUES ('Amir', 'Khan')");
//display the information
$result = mysql_query ("SELECT * FROM newone");
while($row = mysql_fetch_array($result))
{
print ("Added record: " . $row["firstName"]." ".$row["lastName"]." <br>\n");
}
//close user connection
mysql_close();
?>
</body>
</html>

Timotheos

5:02 pm on Aug 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this little script. I think you might want to force the user name to be blank rather then to rely on the default.

<?php
$link = mysql_connect('localhost', '', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

Another helpful tool is phpMyAdmin [phpmyadmin.net]