Jump to content


Photo

Connection issues


  • Please log in to reply
5 replies to this topic

#1 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 14 May 2006 - 05:53 PM

Hi guys,

I have created a login page and am having problems with the connection to the database. Under $myhost I have entered the IP address for the MYSQL databse I have, however when I run the login script I get the following error:

[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/fhlinux245/h/blah.cocom/user/htdocs/join_form2.php on line 117

Warning: mysql_select_db(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/fhlinux245/h/blah.com/user/htdocs/join_form2.php on line 125

Warning: mysql_select_db(): A link to the server could not be established in /home/fhlinux218/h/blah.com/user/htdocs/join_form2.php on line 125[!--colorc--][/span][!--/colorc--]

Should I be entering something more specific for the $myhost or is this error something completly different. incidentally on line 117 the code reads:

$mysql = mysql_connect($myhost, $myuser, $mypass);
if(!mysql)
{
$error = "Cannot connect to the database";
return($error);
}

Thanks

Genista

#2 _will

_will
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 14 May 2006 - 05:57 PM

Is your MySQL server running? Also, in your code, change the if statement to

if (!$mysql) {
  //...


#3 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 14 May 2006 - 06:17 PM

Excuse me, but how do I check its running?

G



[!--quoteo(post=373801:date=May 14 2006, 12:57 PM:name=_will)--][div class=\'quotetop\']QUOTE(_will @ May 14 2006, 12:57 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Is your MySQL server running? Also, in your code, change the if statement to

if (!$mysql) {
  //...
[/quote]





#4 .josh

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

Posted 14 May 2006 - 07:49 PM

try changing $host to 'localhost'
$host = 'localhost';


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 :)

#5 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 14 May 2006 - 08:06 PM

Just tried it - got the same error.
I can use phpmyadmin to insert records into the database, does this mean it is on?

G

[!--quoteo(post=373822:date=May 14 2006, 02:49 PM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ May 14 2006, 02:49 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
try changing $host to 'localhost'
$host = 'localhost';
[/quote]


#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 14 May 2006 - 08:16 PM

If you can add data through phpmyadmin then your database is working. Normally, you would be able to use the server control panel to access MySQL and that's where you would find the 'connection string' that tells you the database name, your database username, etc. Also, that's where you would allow access/give permission for that username to the selected database. Try this - adjusted to suit - and see what happens.

<?php
// define stuff
$db_host = "localhost"; // most usually
$db_pass = ''; // your database password
$db_login = ''; // your database username
$db_name = ''; // your database name

mysql_connect($db_host, $db_login, $db_pass) or die ("Error: Unable to connect"); 
mysql_select_db($db_name) or die ("Error: Unable to open the database."); 

// ... more code ...

Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users