Jump to content

problem with mysql_connect() with newly inherited website


janowicz

Recommended Posts

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

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?

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

"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.

 

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.