Forums

PHP

This topic is locked

Can't connect to local MySQL server through socket

Posted 14 Dec 2011 17:17:05
1
has voted
14 Dec 2011 17:17:05 miguel angel posted:
I Have these error and I can't login to my admin page because of that.

Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /var/www.sit.com/lib/adodb5/drivers/adodb-mysql.inc.php on line 364

Fatal error: Call to a member function SetFetchMode() on a non-object in /var/www.sit.com/core/db.php on line 12

adodb-mysql.inc.php

/ returns concatenated string
        // much easier to run "mysqld --ansi" or "mysqld --sql-mode=PIPES_AS_CONCAT" and use || operator
        function Concat()
        {
                $s = "";
                $arr = func_get_args();
                
                // suggestion by andrew005@mnogo.ru
                $s = implode(',',$arr); 
                if (strlen($s) > 0) return "CONCAT($s)";
                else return '';
        }
        
        function OffsetDate($dayFraction,$date=false)
        {               
                if (!$date) $date = $this->sysDate;
                
                $fraction = $dayFraction * 24 * 3600;
                return $date . ' + INTERVAL ' .  $fraction.' SECOND';
                
//              return "from_unixtime(unix_timestamp($date)+$fraction)";
        }
        
        // returns true or false
        function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
        {
                if (!empty($this->port)) $argHostname .= ":".$this->port;
                
                if (ADODB_PHPVER >= 0x4300)
                        $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,
                                                                                                $this->forceNewConnect,$this->clientFlags);  LINE 364
                else if (ADODB_PHPVER >= 0x4200)
                        $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,
                                                                                                $this->forceNewConnect);
                else
                        $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword);
        
                if ($this->_connectionID === false) return false;
                if ($argDatabasename) return $this->SelectDB($argDatabasename);
                return true;    
        }
 


db.php

<?php

class DB {
        
        private static $instance = null;

        public static function getInstance($dbname, $debug = false) {
                if (!isset(self::$instance[$dbname]) || is_null(self::$instance[$dbname])) {
                        if (isset($GLOBALS['db'][$dbname])) {
                                $ADODB_COUNTRECS = false;
                                self::$instance[$dbname] = &ADONewConnection($GLOBALS['db'][$dbname]['dsn']);
                        self::$instance[$dbname]->SetFetchMode(ADODB_FETCH_ASSOC);
                                self::$instance[$dbname]->Execute("SET NAMES {$GLOBALS['db'][$dbname]['charset']}");
                        }
                }
                self::$instance[$dbname]->debug = $debug;
                return self::$instance[$dbname];
        }
        
}

?>

I've been pulling my hair with this problem, I really need to find the solution!

Replies

Replied 16 Dec 2011 11:20:42
16 Dec 2011 11:20:42 Patrick Woldberg replied:
the second error is a result of the first warning where it tells you it couldn't connect to the database. Check if the host, username and password etc. are correct.
This reply was removed on 4/25/2012 12:21:54 PM.
See the changelog

Reply to this topic