Jump to content

Connection issues


genista

Recommended Posts

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:

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

Thanks

Genista
Link to comment
Share on other sites

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) [snapback]373801[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Is your MySQL server running? Also, in your code, change the if statement to

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



Link to comment
Share on other sites

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) [snapback]373822[/snapback][/div][div class=\'quotemain\'][!--quotec--]
try changing $host to 'localhost'
$host = 'localhost';
[/quote]
Link to comment
Share on other sites

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.

[code]<?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 ...
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.