PDA

View Full Version : Problem creating and loading test php&mysql


jas0995
02-22-2006, 04:07 PM
I am trying to create and load some data into a MySQL database from PHP,
but I am having some problems.

<?php
require ('security.php');

//connect to MySQL;
echo "\ntrying to connect to sql server<br>";
$dbh=mysql_connect ("localhost", "ACC_user", "password")
or die ('I cannot connect to the database because:<br> '
. mysql_error() );


echo "<br><br>selecting current database $database<br>";
//make sure our recently created database is the active one
mysql_select_db ( "aczadb" )
or die ('I cannot select the database because:<br> ' .
mysql_error() );




The result I am getting is:

trying to connect to sql server

selecting current database aczadb
I cannot select the database because:
Access denied for user 'ACC_user'@'localhost' to database 'aczadb'



The connect works fine, but then I am rejected in the select.
The ACC_user account has full privs on the database.

This piece of code is basicly right out of a book. It would seem that
it should work, but I don't understand why I am getting this error.
I looked in the error logs for this domain, and do not find any current
errors.

Anyone got any ideas what I am missing?
Thanks!
-jas

2notch
02-22-2006, 07:39 PM
Shouldn't the database name have a suffix or prefix like ACC_aczadb?
Check your databases in CPanel for the correct db name.

rjewett
02-25-2006, 07:46 AM
The two most common mistakes I make in setting up the php/mysql access, is either not having the user added to the database, or getting the full name of the database correct.

The mysql account maintenance screen lists all of the databases you have created for each the users added to the database. Copy the PHP connection strings exactly as shown on that screen.

jas0995
02-25-2006, 11:55 AM
Shouldn't the database name have a suffix or prefix like ACC_aczadb?
Check your databases in CPanel for the correct db name.

Yep, that was it.

That is what I get for trying to do 34 things at one time.
I am only configured to do 32 things at one time......

Thanks for the help.

-John