peter_anderson Posted October 3, 2009 Share Posted October 3, 2009 I'm having difficulty connecting to the DB. My information is correct (and copied from the cPanel) and on 2 different testing servers, it failed. Error: Warning: mysql_connect() [function.mysql-connect]: Access denied for user '****'@'localhost' (using password: YES) in /*/install.php on line 10 Access denied for user '*****'@'localhost' (using password: YES) (sensitive info removed) Here's the install script: <?php require_once("config.php"); $sql = mysql_connect($host, $user, $pass) or die(mysql_error()); mysql_select_db($db) or die(mysql_error()); //queries removed echo 'Install complete. Remove this file now!!'; Heres config.php <?php //db $host = 'localhost'; $user = 'username'; $pass = 'pass'; $db = 'db'; ?> Can anyone help? It's probably a small mistake. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/176387-mysql_connect-not-connecting-on-2-different-servers/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 3, 2009 Share Posted October 3, 2009 Is the hostname correct? On most shared web hosting, it is not 'localhost' Quote Link to comment https://forums.phpfreaks.com/topic/176387-mysql_connect-not-connecting-on-2-different-servers/#findComment-929669 Share on other sites More sharing options...
d.shankar Posted October 3, 2009 Share Posted October 3, 2009 Wat webhost you are using ? You can find the php to mysql connection code in PHP if you are using godaddy hosting. Quote Link to comment https://forums.phpfreaks.com/topic/176387-mysql_connect-not-connecting-on-2-different-servers/#findComment-929670 Share on other sites More sharing options...
peter_anderson Posted October 3, 2009 Author Share Posted October 3, 2009 The first server is a directadmin one (my own) with localhost as the host. The second one is a cPanel one from a friend with localhost as the host. It's an odd problem - other scripts I've coded work on the directadmin one. Quote Link to comment https://forums.phpfreaks.com/topic/176387-mysql_connect-not-connecting-on-2-different-servers/#findComment-929672 Share on other sites More sharing options...
d.shankar Posted October 3, 2009 Share Posted October 3, 2009 For cpanel , you have to create a username and password, and associate with the database. so u have to include the username and password too along with dbname and hostname Quote Link to comment https://forums.phpfreaks.com/topic/176387-mysql_connect-not-connecting-on-2-different-servers/#findComment-929676 Share on other sites More sharing options...
peter_anderson Posted October 3, 2009 Author Share Posted October 3, 2009 For cpanel , you have to create a username and password, and associate with the database. so u have to include the username and password too along with dbname and hostname I've done that aswell. DirectAdmin doesn't require that. Quote Link to comment https://forums.phpfreaks.com/topic/176387-mysql_connect-not-connecting-on-2-different-servers/#findComment-929678 Share on other sites More sharing options...
d.shankar Posted October 3, 2009 Share Posted October 3, 2009 cPanel doesnt need hostname though.. localhost will do. I had no problems in connecting... Quote Link to comment https://forums.phpfreaks.com/topic/176387-mysql_connect-not-connecting-on-2-different-servers/#findComment-929679 Share on other sites More sharing options...
MadTechie Posted October 3, 2009 Share Posted October 3, 2009 Common mistake with cPanel is the database name and username have an account name prefix.. ie My account is MadTechie, I create a database called 'jobs', I then create a User called 'Techie' password '123' then I assign him to the jobs database (full access) I assume thats where your at now.. now to connect Now my database name is 'MadTechie_jobs', username is 'MadTechie_Techie', password is '123' Quote Link to comment https://forums.phpfreaks.com/topic/176387-mysql_connect-not-connecting-on-2-different-servers/#findComment-929683 Share on other sites More sharing options...
peter_anderson Posted October 3, 2009 Author Share Posted October 3, 2009 Thanks for the help so far, everyone, but it still isn't working. I've added the username_ before it, and linked DBs (for the cpanel test), but it doesn't work. I've probably spelt something wrong, so I'll have another check Quote Link to comment https://forums.phpfreaks.com/topic/176387-mysql_connect-not-connecting-on-2-different-servers/#findComment-929687 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.