API15

API15:JDatabaseMySQL/ construct

From Joomla! Documentation

Revision as of 22:15, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Database object constructor <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Description

Database object constructor

[Edit Descripton]

Template:Description:JDatabaseMySQL/ construct

Syntax

__construct($options)
Parameter Name Default Value Description
$options List of options used to configure the connection

Defined in

libraries/joomla/database/database/mysql.php

Importing

jimport( 'joomla.database.database.mysql' );

Source Body

function __construct( $options )
{
        $host           = array_key_exists('host', $options)    ? $options['host']              : 'localhost';
        $user           = array_key_exists('user', $options)    ? $options['user']              : '';
        $password       = array_key_exists('password',$options) ? $options['password']  : '';
        $database       = array_key_exists('database',$options) ? $options['database']  : '';
        $prefix         = array_key_exists('prefix', $options)  ? $options['prefix']    : 'jos_';
        $select         = array_key_exists('select', $options)  ? $options['select']    : true;

        // perform a number of fatality checks, then return gracefully
        if (!function_exists( 'mysql_connect' )) {
                $this->_errorNum = 1;
                $this->_errorMsg = 'The MySQL adapter "mysql" is not available.';
                return;
        }

        // connect to the server
        if (!($this->_resource = @mysql_connect( $host, $user, $password, true ))) {
                $this->_errorNum = 2;
                $this->_errorMsg = 'Could not connect to MySQL';
                return;
        }

        // finalize initialization
        parent::__construct($options);

        // select the database
        if ( $select ) {
                $this->select($database);
        }
}

[Edit See Also] Template:SeeAlso:JDatabaseMySQL/ construct

Examples

<CodeExamplesForm />