+ Reply to Thread
Results 1 to 4 of 4

Thread: Trouble Connecting to SQL database

  1. #1
    Banned aceman67 has become well known aceman67 has become well known aceman67 has become well known aceman67's Avatar
    Join Date
    Nov 2004
    Location
    Coalhurst Alberta, Canada
    Posts
    2,900
    Thanks
    11
    Thanked 183 Times in 148 Posts

    Trouble Connecting to SQL database

    I'm trying to set up a World of Warcraft Item Stats plugin on my Blog, and I get a cannot connect to database error.

    Here's the full error

    Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/usr/local/mysql-5.0/data/mysql.sock' (2) in /*full path hidden*/html/itemstats/includes/sqlhelper.php on line 30
    string(40) "Unable to connect to SQL host: localhost"
    I know that my host requires the name of the actual database server and not Localhost, I'm just stuck as to where I would need to change the code to get this to work with my server configuration.

    here's the file code.

    Code:
    <?php
    
    // Simple SQL Helper Class (Hack from the EQDKP sql class)
    class SqlHelper
    {
    
    	var $db;
        var $connected      = false;               // is connected ?
        var $query_id       = 0;                   // Query ID                 @var query_id
        var $record         = array();             // Record                   @var record
        //var $closeConnect   = false;
    
    	function SqlHelper($dbhost, $dbname, $dbuser, $dbpass, $bNewConnection = false)
    	{
            $this->Connect($dbhost, $dbname, $dbuser, $dbpass, $bNewConnection);
    	}
        
        function Connect($dbhost, $dbname, $dbuser, $dbpass, $bNewConnection = false)
        {
            if ($this->connected == true)
                return (false);
                
            if ($bNewConnection == true && isset($GLOBALS["connectionId"]))
            {
                $bNewConnection = false;
                $this->db = $GLOBALS["connectionId"];
            }
            else
            {
                $this->db = mysql_connect($dbhost, $dbuser, $dbpass, $bNewConnection);
            }
            if ($bNewConnection)
                $GLOBALS["connectionId"] = $this->db;
    
            if (!($this->db) || is_null($this->db))
            {
    			var_dump("Unable to connect to SQL host: " . $dbhost);
    			unset($this->db);
                return (false);
            } // This is line 40
    		if (isset($this->db) && !@mysql_select_db($dbname, $this->db))
    		{
    			var_dump("Unable to select the database: " . $dbname);
                /*if ($closeConnect == true)
    			    mysql_close($this->db);*/
    			unset($this->db);
                return (false);
    		}
            $this->connected = true;        
            return (true);
        }
    
    	function close()
    	{
            if ($this->connected == false)
                return (false);
            if (isset($this->db) && $this->db)
            {
    	        if (isset($this->query_id) && $this->query_id)
    	        {
    	            @mysql_free_result($this->query_id);
                    unset($this->query_id);                
    	        }            
                // Cela pose probleme dans le cas de la reutilisation d'une connection
                /*if ($closeConnect == true)
    	            @mysql_close($this->db);*/
            }
            $this->connected == false;
            return (true);
    	}
    
    
        function error()
        {
            $result['message'] = @mysql_error();
            $result['code'] = @mysql_errno();
            
            return $result;
        }
    
        
    	function query($query)
        {	
            if ($this->connected == false)
                return (false);
            
            // Remove pre-existing query resources
            unset($this->query_id);
            
            if ($query != '')
                $this->query_id = @mysql_query($query, $this->db);
            if (!empty($this->query_id))
                return ($this->query_id);
            else
                return (false);
        }
    
    
        function query_first($query)
        {
            if ($this->connected == false)
                return (false);
            
            $this->query($query);
            $record = $this->fetch_record($this->query_id);
            $this->free_result($this->query_id);
            unset($this->query_id);
            return $record[0];
        }
    
    
        function fetch_record($query_id = 0)
        {
            if (!$query_id)
                $query_id = $this->query_id;
            if ($query_id)
            {
                $this->record = @mysql_fetch_array($query_id);
                return $this->record;
            }
            else
            {
                return false;
            }
        }
        
        function free_result($query_id = 0)
        {
            if ($query_id == $this->query_id)
                unset($this->query_id);
            if (!$query_id && isset($this->query_id))
            {
                $query_id = $this->query_id;
                unset($this->query_id);
            }        
            if (is_resource($query_id))
            {
                @mysql_free_result($query_id);
                return true;
            }
            else
            {
                return false;
            }
        }
    }
    ?>

  2. #2
    Otaku know1 may be famous one day know1 may be famous one day know1's Avatar
    Join Date
    May 2005
    Location
    here
    Posts
    270
    Thanks
    0
    Thanked 5 Times in 4 Posts

    Re: Trouble Connecting to SQL database

    Quote Originally Posted by aceman67 View Post
    I'm trying to set up a World of Warcraft Item Stats plugin on my Blog, and I get a cannot connect to database error.
    The PHP looked ok, aside from a few syntax format issues, but it should still run.

    Check your my.cnf config for file paths. Make sure they match your current configuration.

    Check the read/write permissions.
    Last edited by aceman67; Sep 16, 2008 at 10:51 PM.

  3. #3
    Banned aceman67 has become well known aceman67 has become well known aceman67 has become well known aceman67's Avatar
    Join Date
    Nov 2004
    Location
    Coalhurst Alberta, Canada
    Posts
    2,900
    Thanks
    11
    Thanked 183 Times in 148 Posts

    Re: Trouble Connecting to SQL database

    I know what the name of my database server is, otherwise I couldn't get my blog to work, what I am having trouble with is getting this particular script to connect to my database. It is trying to connect to Localhost, which doesn't work my server. I want to change it so that it can connect directly to my database servers URL.

  4. #4
    Grouchy Old Anime Otaku LenMiyata has become well known LenMiyata has become well known LenMiyata has become well known LenMiyata's Avatar
    Join Date
    Jan 2005
    Location
    Silicon Valley, California
    Posts
    5,477
    Thanks
    0
    Thanked 172 Times in 147 Posts

    Re: Trouble Connecting to SQL database

    Grumble Grumble Grumble

    I don't suppose its possible to make the socket call by the 'local-host' IP address of 127.0.0.1????
    FAVOURITE THREADS EXPLAIN why, or risk an infraction.
    Rantings of a Grouchy Old Anime Otaku

+ Reply to Thread

Similar Threads

  1. Here comes trouble.
    By Mobius in forum Introductions
    Replies: 9
    Last Post: Jun 04, 2008, 08:48 PM
  2. Having trouble
    By NevesElocin in forum Archived Souls
    Replies: 4
    Last Post: Mar 11, 2007, 06:31 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts