janowicz Posted April 23, 2008 Share Posted April 23, 2008 hi all i've just 'inherited' a website which uses mysql_connect() function. i'running Xampp for local development/testing - incidentally i'm running php4 at localhost as this is what the site was written in. the mysql database dump imported successfully via phpmyadmin (i use 'dbname' and 'password' for example here) all the relevant php stuff to connect seems fine (i've triple checked username & pass) - for example: $link = mysql_connect ("localhost", "dbname", "password") or die ("Could not connect"); mysql_select_db($db); however, when the script runs i'm getting the following error on the webpage: Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'dbname'@'localhost' (using password: YES) in C:\XamppServer\xampp\htdocs\abc-xyz\ connect.php on line 3 Could not connect Can anyone offer any advice please??? many thanks in advance Link to comment https://forums.phpfreaks.com/topic/102534-problem-with-mysql_connect-with-newly-inherited-website/ Share on other sites More sharing options...
DarkWater Posted April 23, 2008 Share Posted April 23, 2008 Your passwords must not be right..that's the only thing really. o-o Link to comment https://forums.phpfreaks.com/topic/102534-problem-with-mysql_connect-with-newly-inherited-website/#findComment-524956 Share on other sites More sharing options...
TEENFRONT Posted April 23, 2008 Share Posted April 23, 2008 erm.. is dbname the username? or just the dbname? you should have 4 things host - localhost, dbname - the database name, username - the db username, and pass - the db password. if you mhave all those and not just dbname then maybe dbname doesnt have privialages set to access the db? Link to comment https://forums.phpfreaks.com/topic/102534-problem-with-mysql_connect-with-newly-inherited-website/#findComment-524979 Share on other sites More sharing options...
janowicz Posted April 23, 2008 Author Share Posted April 23, 2008 thanks for the responses dark water: the password i use is the one i've applied to 'localhost' in xampp - would'nt this apply to all locally tested connections? i have tried with the password used in the original files i inherited but i get exactly the same result - would there be anything in the database overruling the password? teenfront: 'dbname' is the database name i use for this forum post, and not the user name - glad you pointed this out as the original mysql_connect() function link code is as follows: $link = mysql_connect ("localhost", "dbname", "password") or die ("Could not connect"); (of course this is not the real password!) so ... it would seem that the actual username is missing from the original mysql_connect () function Herein lies another problem - i don't have the original username nor will i be able to get it, so is there a way i can get round this? thanks in advance Link to comment https://forums.phpfreaks.com/topic/102534-problem-with-mysql_connect-with-newly-inherited-website/#findComment-525041 Share on other sites More sharing options...
TEENFRONT Posted April 23, 2008 Share Posted April 23, 2008 "dbname" should be the db username, not the db name itself. so you need the username. UNLESS the username IS the same as the database name... then your ok, but it should be working for you. Create another user for the DB. you cpanel or other? set up a new user and give access to the db. Link to comment https://forums.phpfreaks.com/topic/102534-problem-with-mysql_connect-with-newly-inherited-website/#findComment-525091 Share on other sites More sharing options...
craygo Posted April 23, 2008 Share Posted April 23, 2008 use a little error checking till you get it fixed. <?php $link = @mysql_connect ("localhost", "dbname", "password") or die ("Could not connect to localhost! Error: ".mysql_error()); @mysql_select_db($db, $link) or die("Could not connect to database! Error: ".mysql_error()); Ray Link to comment https://forums.phpfreaks.com/topic/102534-problem-with-mysql_connect-with-newly-inherited-website/#findComment-525104 Share on other sites More sharing options...
janowicz Posted April 24, 2008 Author Share Posted April 24, 2008 thanks teenfront - connected now Link to comment https://forums.phpfreaks.com/topic/102534-problem-with-mysql_connect-with-newly-inherited-website/#findComment-525847 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.