pocobueno1388 Posted June 11, 2006 Share Posted June 11, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/11682-connecting-to-database-wont-work/ Share on other sites More sharing options...
.josh Posted June 11, 2006 Share Posted June 11, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/11682-connecting-to-database-wont-work/#findComment-44202 Share on other sites More sharing options...
joquius Posted June 11, 2006 Share Posted June 11, 2006 how about taking away the quotes from the string values? $db and not "$db" Quote Link to comment https://forums.phpfreaks.com/topic/11682-connecting-to-database-wont-work/#findComment-44246 Share on other sites More sharing options...
pocobueno1388 Posted June 12, 2006 Author Share Posted June 12, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/11682-connecting-to-database-wont-work/#findComment-44768 Share on other sites More sharing options...
.josh Posted June 12, 2006 Share Posted June 12, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/11682-connecting-to-database-wont-work/#findComment-44772 Share on other sites More sharing options...
pocobueno1388 Posted June 13, 2006 Author Share Posted June 13, 2006 Okay...I will hunt around for that information. Hopefully that is the only problem, I am anxious to get started on my new project. Quote Link to comment https://forums.phpfreaks.com/topic/11682-connecting-to-database-wont-work/#findComment-44834 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.