Jump to content

[SOLVED] Connecting to the Database


cheechm

Recommended Posts

Hi,

I can't seem to be able to connect to a database.

 

functions.php

require_once 'config.php';

class DBConnect extends SystemComponent {

    var $theQuery;
    var $link;

    //*** Function: DbConnect, Purpose: Connect to the database ***
    function DBconnect(){

        // Load settings from parent class
        $settings = SystemComponent::getSettings();

        // Get the main settings from the array we just loaded
        $host = $settings['dbhost'];
        $db = $settings['dbname'];
        $user = $settings['dbusername'];
        $pass = $settings['dbpassword'];

        // Connect to the database
        $this->con = mysql_connect("$host", "$user", "$pass") or die(mysql_error());
        mysql_select_db("$db", $this->con);
        register_shutdown_function(array(&$this, 'close'));

    }

    //*** Function: query, Purpose: Execute a database query ***
    function query($query) {

        $this->theQuery = $query;
        return mysql_query($query, $this->con);

    }
    

    //*** Function: fetchArray, Purpose: Get array of query results ***
    function fetchArray($result) {

        return mysql_fetch_array($result);


    

    //*** Function: close, Purpose: Close the connection ***
    function close() {

        mysql_close($this->con);
    }
  

}


}

 

config.php

class SystemComponent {

    var $settings;

    function getSettings() {

        // System variables
        $settings['siteDir'] = '****';

        // Database variables
        $settings['dbhost'] = '****;
        $settings['dbusername'] = '***';
        $settings['dbpassword'] = '***';
        $settings['dbname'] = '***';


        return $settings;

    }

}

 

I get this error when trying to connect to the database:

Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'sql12.streamline.net' (4) in functions.php on line 26

Can't connect to MySQL server on 'sql12.streamline.net' (4)

 

What is the problem?

Many thanks.

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.