Jump to content

Help With Php/mysql


Recommended Posts

I am in the process of moving my site from another host to here. A few of my pages use a mysql database. I created the database, populated it (with a dump from the old one), changed the config files to point to the correct database, but it's giving me an error:


>Warning: mysql_connect() [function.mysql-connect]: Access denied for user: 'lunarmagic@localhost' (Using password: YES) in /home/lunardr/public_html/index.php on line 46
Couldn't connect to MySQL


I'm not really sure what to do about it, since it worked fine on my old site. Could someone please let me know if there's anything I should be doing differently? Here's my connection code...



$db = mysql_connect($server, $username, $password);
if (! $db)
die("Couldn't connect to MySQL");
mysql_select_db($database,$db) or die("Select DB Error: ".mysql_error());


$server is set to "localhost", username and password I set up in the database manually.



Link to comment
Share on other sites

You don't need to create a new user to access the database. Your Cpanel username and password should work just fine.


Just a little advice, change the line


die("Couldn't connect to MySQL");




die("Couldn't connect to MySQL: " . mysql_error());


It will provide you with more information on the error.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...