Connecting to MYSQL Database


AquaMorph

Recommended Posts

I am using code that looks like this:



<?php

	 $db_con = mysql_connect("localhost","root","abc123");

	 if (!$db_con){

		  die('Could not connect: ' . mysql_error());

	 }

	 mysql_select_db("my_data", $db_con);

?>

I am trying to connect to a MYSQL Database I made, but the script keeps returning an error "Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in /home/teampyro/public_html/scout/config.php on line 2

Could not connect: Access denied for user 'root'@'localhost' (using password: YES)"

This is a very noobish question but how should I connect to my database?

Link to comment
Share on other sites

I would advise making a MySQL user and attaching it to the database you wish to use rather than using the cPanel username. You can do this using the MySQL page in cPanel. The reason is if you ever change your cPanel password then you need to update your application configuration to reflect that change.

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.
Note: Your post will require moderator approval before it will be visible.

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

Loading...