Im presently writing a script which is run like a cronjob to complete some information using values from the joomla database, As this script won't be utilized via joomla like a wordpress plugin etc i have to do DB connections by using it.

What im trying to complete is make use of the Joomla framework to complete everything(Connection, queries, etc) for security as well as portability reasons (rather than getting another group of the login qualifications within this script its all handled through the Joomla config)

I've done the very best i'm able to however when i run the script i recieve the next error:

Database Error: Unable to connect to the database:Could not connect to MySQL

I've printed the variable making certain the bond particulars for mysql are correct (that they are).

My Current Code is:

<?php
//init Joomla Framework
define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/..' ));
define( 'DS', DIRECTORY_SEPARATOR );

require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once( JPATH_CONFIGURATION   .DS.'configuration.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'database.php' );
require_once ( JPATH_LIBRARIES .DS.'joomla'.DS.'import.php' );

//DB Connection
$Config = new JConfig();

$option['driver']   = $Config->dbtype;   // Database driver name
$option['host']     = $Config->host;     // Database host name
$option['user']     = $Config->user;     // User for database authentication
$option['password'] = $Config->password; // Password for database authentication
$option['database'] = $Config->db;       // Database name
$option['prefix']   = $Config->dbprefix; // Database prefix (may be empty)

$db = & JDatabase::getInstance($option);

//DBQuery
$database =& JFactory::getDBO();
$query = "SELECT * FROM #__chronoforms_RD_NonDangerousGoods WHERE cf_id = 4;";
$database->setQuery($query);
$result = $database->query();
print_r($result);
?>

do this

   <?php
        //init Joomla Framework
        define( '_JEXEC', 1 );
        define( 'DS', DIRECTORY_SEPARATOR );
        define( 'JPATH_BASE', realpath(dirname(__FILE__).DS.'..' ));


        require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
        require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

        $mainframe = JFactory::getApplication('site');

        //DBQuery
        $database =& JFactory::getDBO();
        $query = "SELECT * FROM #__chronoforms_RD_NonDangerousGoods WHERE cf_id = 4;";
        $database->setQuery($query);
        $result = $database->query();
        print_r($result);
    ?>