Jump to content

Archived

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

pocobueno1388

Connecting to database won't work.

Recommended Posts

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

Share this post


Link to post
Share on other sites
change your code to this:
[code]
<?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());
?>
[/code]
and post the error message.

Share this post


Link to post
Share on other sites
how about taking away the quotes from the string values? $db and not "$db"

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


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

Share this post


Link to post
Share on other sites

×

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.