Page 1 of 1

My Sql connect Error

Posted: Mon Mar 15, 2010 9:15 am
by doriskashyap
i am working on a script and according to me i m doing everything right but i m still getting this error

Code: Select all

 
Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /hermes/bosweb/web022/b220/glo.mumbaindians/members/config.inc.php on line 17
 
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /hermes/bosweb/web022/b220/glo.mumbaindians/members/config.inc.php on line 18
 
Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /hermes/bosweb/web022/b220/glo.mumbaindians/members/config.inc.php on line 27
 
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /hermes/bosweb/web022/b220/glo.mumbaindians/members/config.inc.php on line 27
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
 
the code i m using is

Code: Select all

 
<?php
set_magic_quotes_runtime(0);
$config['host'] = 'mumbaindians.globatmysql.com';
$config['user'] = 'username';
$config['pass'] = 'pwd';
$config['dbname']  = 'mumbai';
$config['sourceRoot'] = '/MacintoshHD/users/Doris/Desktop/socialnetworkpractise/Members';
$config['siteRootUrl'] = 'http://members.mumbaindiansclub.com/';
$config['siteUrlFolder'] = '/members';
$config['boardStartDate'] = 'February 01, 2010';
 
define('INSTALLED', true);
 
 
 
$tableprefix ="";
[color=#FF0000]$config['link'] = mysql_connect($config['mumbaindians.globatmysql.com'],$config['username'],$config['pwd']);[/color]
[color=#FF0000]$config['db'] = mysql_select_db($config['mumbai'],$config['link']);[/color]
$config['pathSrcInclude'] = $config['sourceRoot'] . 'src/';
$config['pathForums'] = $config['sourceRoot'].'forums/';
$config['pathIncludes'] = $config['sourceRoot'].'includes/';
$config['pathBlog'] = $config['sourceRoot'].'blog/';
 
 
 
//fetching site name 
[color=#FF0000]$sitename=mysql_query("SELECT sitename FROM site_custom_settings") or die(mysql_error());[/color]
if(mysql_num_rows($sitename)>0) 
{ 
        $PSiteName=mysql_result($sitename,0,'sitename'); 
}//end if 
 
 
//fetching site admin email 
$adminEmail=mysql_query("select Email from admin_users where GroupId='1'") or die(mysql_error()); 
if(mysql_num_rows($adminEmail)>0) 
{ 
        $adminEmail=mysql_result($adminEmail,0,'Email'); 
}//end if 
 
 
 
// Site Status
// Only for front end.
if (strstr($_SERVER['SCRIPT_NAME'], 'admin/')==FALSE) {
$rs_site = mysql_query("SELECT * FROM site_settings") or die(mysql_error());
$rw_site = mysql_fetch_row($rs_site);
if ($rw_site['site_live']=='0')
{
//site down for maintenance
header("location: maintenance.php");
exit;
}
}
/***** Title and Links *****/
 
$config['fromMail'] = $adminEmail;
$config['fromName'] = $PSiteName;
$config['admin'] = 'Admin';
$config['adminMail'] = $adminEmail;
$config['siteTitleLink'] = 'Welcome to '.$PSiteName.' - Dating Solutions';
$config['project'] = $PSiteName;
$config['siteAdminTitle'] = $PSiteName.' - Secure Administrative Suite';
$_SESSION['fromMail_Mail'] = $adminEmail;
/***** Site Settings *****/
 
$config['currency'] = '&pound';
 
/***** Images ******/
 
$config['noImage'] = 'noimage.gif';
$config['resizeQuality'] = 60;
$config['thumbWidth'] = 50;
$config['thumbHeight'] = 38;
$config['imageWidth'] = 130;
$config['imageHeight'] = 150;
$config['photoUploadLimit'] = 4;
$config['photoAlbumUploadLimitFreeUser'] = 5;
/****** Admin ******/
 
$config['timeoutOnline'] = '1200'; // Online
$config['timeoutVisit'] = '60'; // Idle
$config['uploadLimit'] = '1500000';
$config['uploadNumber'] = '8';
/******** Miscellaneous ******/
 
$config['mailsPerPage'] = '20';
$config['selectText'] = '---Select---';
// -- Include Cart Class
require_once($config['pathSrcInclude'].'cart_class.php');
ob_start(); 
session_start(); 
define("GROUP_HIDDEN_MSG", "This group is hidden. You cannot view this group.");
 
// -- Instantiate Cart Class
if ($_SESSION['cart']=='')
{
$cart = new cart();
$_SESSION['cart'] = $cart;
}
else{$cart = $_SESSION['cart'];}
function validateSession()
{
$rsOnline = mysql_query("Select * from online where MemberId = '".$_SESSION['sessionMemberId']."'") or die(mysql_error());
if (mysql_num_rows($rsOnline)=='0')
{
session_destroy();
 
//if user not login store the quiz id and user quiz value into session variable for further process
if(isset($_POST['btnAnswer']) && $_POST['btnAnswer']=='Submit')
{
 
            session_start();
            if (get_magic_quotes_gpc())
            {
                    $qcid = stripslashes($_GET['qcid']);
            }//end if
            else {
                    $qcid = $_GET['qcid'];
            }//end else
            $_SESSION['QuizcategoryId']=$qcid;
            //all category listing
            $query =  mysql_query("select * from tbl_Quizzes where qcid='".$qcid."'") or die(mysql_error());
            $count=mysql_num_rows();
            for($i=1;$i<=$count;$i++)
            {
                    $Ans='Ans'.$i;
            $_SESSION[$Ans]=$_POST[$Ans];
            }//end for loop
}//end if
 
$redirecturi = base64_encode($_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING']);
$redirectpath = $GLOBALS['config']['siteRootUrl']. 'userlogin.php?redirecturi='.$redirecturi;
header("Location: $redirectpath");
exit;
}
}
// Check if cookie already exists
// Retrieve the member id
// Redirect it to homepage
// Make necessary sessions
 
 
 
if (!(isset($_SESSION['sessionMemberId'])))
{
$member = $_COOKIE['memberid'];
if ($member!='')
{
// Cookie is set
// Autologin this member
 
 
$id = base64_decode($member);
$rs = mysql_query("SELECT members.*, online.LoggedOn  from members  LEFT JOIN online ON (members.MemberId = online.MemberId) where members.MemberId = '$id' ") or die(mysql_error());
if (mysql_num_rows($rs)>0)
{
$rw = mysql_fetch_array($rs);
 
// DEFAULT VISIBLE
$visible = 'Y';
$_SESSION['sessionMemberId'] = $rw[MemberId];
$_SESSION['sessionScreenName'] = $rw[ScreenName];
$_SESSION['sessionMemberEmail'] = $rw[Email];
$_SESSION['sessionIsAdmin'] = ($rw[Admin]=='Y') ? TRUE : FALSE;
$now = time();
/* User is loggin for the first time */
 
mysql_query("Update members set LastLogin = '".$now."' where MemberId = '".$rw[MemberId]."' ") or die(mysql_error());
if ($rw['LoggedOn'] == '')
{
// No entry in the online table
 
$sqlOnline = "INSERT INTO online(MemberId , LoggedOn, ActiveTill, Idle, Visible) VALUES('".$rw[MemberId]."', '".$now."','".$now."',0, '".$visible."')";
mysql_query() or die(mysql_error());
}
else
{
$sqlUpdate = "UPDATE online SET LoggedOn='".$now."', ActiveTill='".$now."', Visible='".$visible."', Idle=0 WHERE MemberId='".$rw[MemberId]."'";
mysql_query() or die(mysql_error());
}
header("Location: home.php");
exit;
}
}
}
 
?>
 
PLEASE HELP

Re: My Sql connect Error

Posted: Mon Mar 15, 2010 12:27 pm
by cpetercarter
I think that this line :

Code: Select all

 
$config['link'] = mysql_connect($config['mumbaindians.globatmysql.com'],$config['username'],$config['pwd']);
 
should be

Code: Select all

 
$config['link'] = mysql_connect($config['host'],$config['user'],$config['password']);
 

Re: My Sql connect Error

Posted: Wed Mar 17, 2010 7:45 am
by doriskashyap
mumbaindians.globatmysql.com is the host name only

Re: My Sql connect Error

Posted: Wed Mar 17, 2010 8:01 am
by aravona
Most DB connects I've used just use 'localhost' for the host... have you tried that?

Eliminate the obvious :) (and really should have put something that long in code tags)

Re: My Sql connect Error

Posted: Wed Mar 17, 2010 3:05 pm
by infolock
Also, have you even tried connecting to the server via console? make sure the db server is even up. most socket errors that i know of either relate to the server not being up, or a configuration problem (which is like 3% of the time).

Re: My Sql connect Error

Posted: Wed Mar 17, 2010 3:09 pm
by Benjamin
Please use

Code: Select all

tags when posting code in the forums.

Re: My Sql connect Error

Posted: Thu Mar 18, 2010 1:50 am
by cpetercarter
There may be multiple problems, as infolock and aravona suggest.

But one problem, which you need to sort out first, is the fact that you are using $config['mumbaindians.globatmysql.com'], $config['username'] and $config['pwd'] without defining them.

The offsets which you have defined are $config['host'], $config['user'] and $config['password'], and that is why I think you should be using these in your connect statement. However, as infolink points out, "host" is nearly always "localhost" (your database/server admin can confirm this for you) so you may need to amend line 4. And you have put your real username and password into lines 5 and 6, haven't you?

PS You seem to have removed part of the code from your original posting. You need to connect to the database before you can run queries.