JDatabaseMySQL/ construct: Difference between revisions
From Joomla! Documentation
m removing red link to edit, no existant pages |
m clean up |
||
| Line 2: | Line 2: | ||
Database object constructor | Database object constructor | ||
<! removed transcluded page call, red link never existed > | <! removed transcluded page call, red link never existed > | ||
| Line 62: | Line 60: | ||
</source> | </source> | ||
<! removed transcluded page call, red link never existed > | <! removed transcluded page call, red link never existed > | ||
Revision as of 13:47, 24 March 2017
Description
Database object constructor
<! removed transcluded page call, red link never existed >
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->_connection = @mysql_connect($host, $user, $password, true))) {
$this->_errorNum = 2;
$this->_errorMsg = 'Could not connect to MySQL';
return;
}
// Finalize initialisation
parent::__construct($options);
// select the database
if ($select) {
$this->select($database);
}
}
<! removed transcluded page call, red link never existed >
Examples
<CodeExamplesForm />