FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP script has MSQL access denied





steveadams617
I'm getting an access denied error. I suspect it's the host name or version problems with passwords or something simple. It's running locally fine on windows 2000, apache, MySQL 5. I have plugged the following into data access class:

(changed to protect my privacy)

$CCConnectionSettings = array (
"MyInfo" => array(
"Type" => "MySQL",
"Database" => "johnaja_myinfo",
"Host" => "john.frih.net",
"Port" => "",
"User" => "johnaja_john",
"Password" => "PASSWORD",
"Persistent" => true
)

I get the following in the browser when I try to access a page that makes it's first call to the database. Any idea where lyeredtech.com is coming from? I've never heard of them. Thanks:

Warning: mysql_pconnect(): Access denied for user: 'johnaja_john@ltsv.layeredtech.com' (Using password: YES) in /home/johnaja/domains/john.frih.net/public_html/myinfo/db_mysql.php on line 97
Database error: cannot connect to Database Access denied for user: 'johnaja_john@ltsv.layeredtech.com' (Using password: YES)
MySQL Error
Session halted.
JustaMin
Try ths, just include it on any page you need a connection:

Code:

<?
ob_start();
//## Connect ##//
//Server
$host="localhost";
$user="USERNAME";
$password="PASSWORD";

$connection = mysql_connect($host,$user,$password)
or die (header("Location: dbdown.php"));

//Database
$database = "DBNAME";
$db = mysql_select_db($database,$connection)
or die ("Couldn’t select database.");

ob_end_flush();
?>


Change dbdown.php to an error page if your database is unnavailable, or remove 'or die (header("Location: dbdown.php"))' if you don't want that.

Dont forget to close the connection at the end of each script:

Code:

<? if (isset($connection)){ mysql_close($connection); } ?>


Hope that heps, if it doesnt work you're entering either the wrong username, password or database name as this is what I use and it works fine.

PS, dont put your password on the forum!!
steveadams617
Your code gave me the clue I needed. It was using localhost rather than my domain as the server name. I should have thought of that. Something told me MySQL might be running on another box.

Never fear, I did not post any of my real information. Password and everything else was all changed for the sample code I posted.

Thanks again.
Related topics
Norton Systemworks 2003 - Access Denied : Drive C
Phoenix free PHP scripts
error in my PHP script
Access denied as Admin in phpNuke
PHP Script- How can we install it
Preventing bad PHP script calls
array check box on php script using $_POST
php script not loading
PHP script authorization monthly
PHP script to create email addresses/ftp accounts/etc...
php script for Changing file permissions & owner
Uploading an Image using PHP script - RESOLVED
Access Denied for user ODBC@localhost
[Help] php script to post to twitter
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.