Jump to content

Archived

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

aaronrb

Unable to connect to database

Recommended Posts

Hi all,
i really aint got a clue what is going on, i have used this code a hundred times before but i don't think it likes my new host.

[a href=\"http://aaron.awardspace.co.uk/home.php\" target=\"_blank\"]an example is here [/a]

i get this error message everything time:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/www/aaron.awardspace.co.uk/db_connect.php on line 10
Couldn't connect to server.[/quote]


and here is my simple to use code:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?
//mysql
$host = "localhost";
$username = "username";
$password = "password";
$database_name = "tkd1987_aaron";

//databsae connection.

$connection = mysql_pconnect("$host","$username","$password")
or die ("Couldn't connect to server.");

$db = mysql_select_db("$database_name", $connection)
or die("Couldn't select database.");
?>[/quote]

Sorry for being a pain if this is just some stupid reading error.
but thanks in advance anyway.

Aaron

Share this post


Link to post
Share on other sites
hello,
mysql_pconnect(); function for connecting mysql server. if you are using a simple database on your website then use mysql_connect(); it is enough.

Thank you,
Karthi keyan.

Share this post


Link to post
Share on other sites
[!--quoteo(post=356475:date=Mar 19 2006, 08:09 PM:name=blazing_bruce)--][div class=\'quotetop\']QUOTE(blazing_bruce @ Mar 19 2006, 08:09 PM) [snapback]356475[/snapback][/div][div class=\'quotemain\'][!--quotec--]
hello,
mysql_pconnect(); function for connecting mysql server. if you are using a simple database on your website then use mysql_connect(); it is enough.

Thank you,
Karthi keyan.
[/quote]

thanks but i have tried that too and i still get the same error!!

Share this post


Link to post
Share on other sites
hello,

The error Can't connect to ... normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket filename or TCP/IP port number when trying to connect to the server.

for more reference about these type of probs [a href=\"http://www.oscommerce.info/kb/osCommerce/General_Information/Common_Problems/69\" target=\"_blank\"]http://www.oscommerce.info/kb/osCommerce/G...mon_Problems/69[/a]

Thank you,
Karthi keyan.

Share this post


Link to post
Share on other sites
i had the same problem i had to remove all the variables for some reason that i do not know it just wouldnt read them the connect code i use now looks like this

[code]

<?
mysql_pconnect('localhost', 'username', 'password')
or die ("Couldn't connect to server.");

mysql_select_db('tkd1987_aaron')
or die("Couldn't select database.");
?>

[/code]


that is the only way i could get mine to connect
hopfully this helps

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.