Click to See Complete Forum and Search --> : [RESOLVED] Can't connect to local MySQL server through socket


gynlorf
10-07-2007, 10:03 PM
This has been bugging me forever...

I have been creating this website with php/mysql(version 5) and everything works perfectly OK except this one page, which gives me this error:
Can't connect to local MySQL server through socket '/usr/local/mysql-5.0/data/mysql.sock' (2)

It cannot be the hostname, password, username, or any of that because I am using the same configuration file as every other page on my website.
This configuration has:
<?php
$dbuser = "xxxxxxxxx";
$dbpass = "xxxxxxxxx";
$dbhost = "xxxxxxxxx"; //not localhost
$dbname = "xxxxxxxxx";
$connection = @mysql_connect($dbhost,$dbuser,$dbpass);
if (!$connection)
{
die ("Could not connect to the database:
<br />". mysql_error());
}
mysql_select_db($dbname) or die(mysql_error());
empty($dbpass);
?>

The page that has the error is:
<?php
include($_SERVER['DOCUMENT_ROOT']."/tweb/config.php");
$beginning = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>ViewPage</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
</head>
<body>
<center>
<table class="settings" align="center">
<tr align="center">
<td class="leftshadow"></td>
<td align="center">
<a href="./"><img src="./banner.png" border="0px" alt="T-Webs"></a><br>
<br>
<br>
<table border=0 align="center">';
$end = '<br>
<br><br><hr>
<table width="628px">
<tr align="center">
<td class="fixalign" align="left">TWebs is a creation by Gynlorf</td><td class="fixalign" align="right"><a href="http://www.gynlorf.com/">Gynlorf.com</a></td>
</tr>
</table><hr>
</td>
<td class="rightshadow"></td>
</tr>
</table>
</center>
</body>
</html>';
$title = "View Page";
include("common2.php");
if(isset($_GET['id']))
{
$id = $_GET['id'];
if(preg_match("/^[0-9]{1,3}$/",$id)==0)
{
header("location:http://www.gynlorf.com/tweb");
}
else
{
print($beginning);
$query = "SELECT * FROM `twebs_pages` WHERE `page_id` = '$id' ORDER BY `twebs_pages`.`order` ASC"; /*this is where the problem happens*/
$result = @mysql_query($query);
if(!$result)
{
print("Error, could not query the database:<br>".mysql_error());
}
else
{
while($row = mysql_fetch_row($result))
{
$id2 = $row[0];
$page_name = $row[4];
echo("<tr><tr><a href='./viewpage.php?id=$id&sec=$id2'>$page_name</a></tr></td>");
}
print("</table>");
}
}
}
else
{
header("location:http://www.gynlorf.com/tweb/twebsites.php");
}
print($end);
?>

and it doesnt work. I am using Godaddy hosting, so I made sure to put in the host it gave me, which works for every other page. What the page is supposed to do, is load my page, then read the table and display the links that have the id from the $_GET['id]; part.

oh yes, one last thing:
here is the contents of common2.php if its needed:
<?php
if($_COOKIE['isloggedin']==true)
{
$login = $_COOKIE['login'];
$password = $_COOKIE['password'];
setcookie("isloggedin",true,time()+1800);
setcookie("login",$login,time()+1800);
setcookie("password",$password,time()+1800);
$query = "SELECT * FROM `twebs_users` WHERE `username` = '$login' AND `password` = '$password' LIMIT 1";
$result = mysql_query($query) OR die("Error querying the database:<br>".mysql_error());
$row = mysql_fetch_row($result);
$id = $row[0];
$page_id = $_GET['id'];
if(preg_match("/^[0-9]{1,3}$/",$id)==0)
{
header("location:http://www.gynlorf.com/tweb");
}
if($id==$page_id)
{
$isadmin = "yes";
}
else
{
$isadmin = "no";
}
}
else
{
$isadmin = "no";
}
mysql_close();
?> which is supposed to see if the user is an admin or not

\\.\
10-08-2007, 06:11 PM
$connection is not in your database selection nor in the query

So this may be why its not connecting.

gynlorf
10-08-2007, 06:24 PM
does it need to be? I have never used $connection in the queries or the selection of databases, so I dont see how that is the problem

NogDog
10-08-2007, 08:00 PM
Which line is failing with that error?

(Also, if you use [php] instead of [code] tags around your code samples, they'll get some handy color highlighting.)

gynlorf
10-08-2007, 08:23 PM
print($beginning);
$query = "SELECT * FROM `twebs_pages` WHERE `page_id` = '$id' ORDER BY `twebs_pages`.`order` ASC"; /*this is where the problem happens*/
$result = @mysql_query($query);
if(!$result)
{
print("Error, could not query the database:<br>".mysql_error());
}
else
{

Yea, noticed the php tags after I posted...

EDIT: Wow, I feel so stupid.I used the mysql_close() command before the mysql_query() command. And now it works :p

\\.\
10-10-2007, 07:44 AM
Well mark thread as resolved from the "Thread Tools"

MrCoder
10-10-2007, 08:32 AM
The most complex problem is always solved with the simplest solution.