Jump to content


Photo

Unable to connect to database


  • Please log in to reply
4 replies to this topic

#1 aaronrb

aaronrb
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 19 March 2006 - 06:45 PM

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


#2 blazing_bruce

blazing_bruce
  • Members
  • PipPip
  • Member
  • 28 posts
  • LocationIndia

Posted 19 March 2006 - 08:09 PM

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.

#3 aaronrb

aaronrb
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 19 March 2006 - 08:12 PM

[!--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) View Post[/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!!

#4 blazing_bruce

blazing_bruce
  • Members
  • PipPip
  • Member
  • 28 posts
  • LocationIndia

Posted 19 March 2006 - 08:58 PM

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.


#5 shortj75

shortj75
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationPort Huron,mi

Posted 20 March 2006 - 06:38 PM

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


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

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



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

hopfully this helps if it doesn't sorry
i won't write the code for you!!! you don't learn that way




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users