Jump to content


Photo

Connecting to database won't work.


  • Please log in to reply
5 replies to this topic

#1 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 11 June 2006 - 02:12 AM

I am having trouble getting connected to my database. Here is the code I am using to do it:

config.PHP
-------------

<?php
$host = "localhost"; // your MySQL host i.e. the server on which the database is, usually localhost
$user = "*****"; // your MySQL username
$pass = "*****"; // your MySQL password
$db = "*****"; // the database to which you're trying to connect to

$conn = mysql_connect("$host", "$user", "$pass") or die ("Unable to connect to database.");
mysql_select_db("$db", $conn);
?>

Of course there are actual values stored in the variables other then the '*****'.

Is there something wrong with this script? I just use the code

include "config.php";

on the top of every script I need it with and it won't work. Any help would be appreciated. Thanks

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 11 June 2006 - 06:19 AM

change your code to this:
<?php
$host = "localhost"; // your MySQL host i.e. the server on which the database is, usually localhost
$user = "*****"; // your MySQL username
$pass = "*****"; // your MySQL password
$db = "*****"; // the database to which you're trying to connect to

$conn = mysql_connect("$host", "$user", "$pass") or die (mysql_error());
mysql_select_db("$db", $conn) or die(mysql_error());
?>
and post the error message.


Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 11 June 2006 - 12:34 PM

how about taking away the quotes from the string values? $db and not "$db"
z..z..z..z..z..z..z..z..

#4 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 12 June 2006 - 11:05 PM

Crayon Violent --> Here is the error I got with your code.

Can't connect to MySQL server on 'localhost' (10061)

joquius--> I got the same error when I took away the quotes.

Any other ideas?

#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 12 June 2006 - 11:13 PM

looks like you are going to have to put your actual sql server name instead of localhost. you will have to rummage around in your host account for that info or contact your host.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#6 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 13 June 2006 - 03:03 AM

Okay...I will hunt around for that information. Hopefully that is the only problem, I am anxious to get started on my new project.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users