/** * Database object constructor * * @access public * @param array List of options used to configure the connection * @since 1.5 * @see bDatabase */ 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); } }
/** * Database object constructor * * @access public * @param array List of options used to configure the connection * @since 1.5 * @see bDatabase */ 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; // Requires the direct server path $driver = array(1 => '{Microsoft Access Driver (*.mdb)}', 2 => '{SQL Server Native Client 10.0}', 3 => '{Microsoft Excel Driver (*.xls)}', 4 => '{SQL Server}', 5 => '{Adaptive Server Anywhere 8.0}'); $provider = array(1 => 'Microsoft.ACE.OLEDB.12.0', 2 => 'Microsoft.Jet.OLEDB.4.0'); $dsn = "" . "Driver={$driver['1']};" . "DriverId=281;" . "Data Source=" . $host . $database . ";" . "DefaultDir=" . $host . ";" . "DATABASE=" . $database . ";" . "Servername=localhost;" . "Port=5432;" . "ReadOnly=Yes;" . "Persist Security Info=False;" . "UID=" . $user . ";" . "PWD=" . $password . ";"; echo $dsn . '<BR><BR>'; // perform a number of fatality checks, then return gracefully if (!function_exists('odbc_connect')) { $this->_errorNum = 1; $this->_errorMsg = 'The ODBC adapter "odbc" is not available.'; return; } //echo $dsn; // connect to the server if (!($this->_resource = odbc_connect($dsn, $user, $password, SQL_CUR_USE_ODBC))) { $this->_errorNum = 2; $this->_errorMsg = 'Could not connect to ODBC'; return; } // finalize initialization parent::__construct($options); // select the database if ($select) { $this->select($database); } }
/** * Database object constructor * @param string Database host * @param string Database user name * @param string Database user password * @param string Database name * @param string Common prefix for all tables */ function __construct($options) { //var_dump_pre($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('mssql_connect')) { $this->_errorNum = 1; $this->_errorMsg = 'The MSSQL adapter "mssql" is not available.'; return; } // connect to the server if (!($this->_resource = @mssql_connect($host, $user, $password, true))) { $this->_errorNum = 2; $this->_errorMsg = 'Could not connect to MSSQL: ' . mssql_get_last_message(); print_r($this->_resource); return; } else { $this->connected = true; } // finalize initializations parent::__construct($options); // select the database if ($select) { $this->select('[' . $database . ']'); } }
/** * Overload object factory for Singleton * * @return null|static */ public static function create() { if (self::$_instance === null) { self::$_instance = parent::create(func_get_args()); } return self::$_instance; }
/** * Create an database object * * @access private * @return object rDatabase * @since 1.5 */ public static function &_createDBO() { global $wpdb; $host = DB_HOST; $user = DB_USER; $password = DB_PASSWORD; $database = DB_NAME; $prefix = $wpdb->prefix; $driver = 'mysql'; $options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix); $db =& bDatabase::getInstance($options); return $db; }
/** * Generic Publish/Unpublish function * * @access public * @param array An array of id numbers * @param integer 0 if unpublishing, 1 if publishing * @param integer The id of the user performnig the operation * @since 1.0.4 */ function publish($cid = null, $publish = 1, $user_id = 0) { JArrayHelper::toInteger($cid); $user_id = (int) $user_id; $publish = (int) $publish; $k = $this->_tbl_key; if (count($cid) < 1) { if ($this->{$k}) { $cid = array($this->{$k}); } else { $this->setError("No items selected."); return false; } } $cids = $k . '=' . implode(' OR ' . $k . '=', $cid); $query = 'UPDATE ' . $this->_tbl . ' SET published = ' . (int) $publish . ' WHERE (' . $cids . ')'; $checkin = in_array('checked_out', array_keys($this->getProperties())); if ($checkin) { $query .= ' AND (checked_out = 0 OR checked_out = ' . (int) $user_id . ')'; } $this->_db->setQuery($query); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); return false; } if (count($cid) == 1 && $checkin) { if ($this->_db->getAffectedRows() == 1) { $this->checkin($cid[0]); if ($this->{$k} == $cid[0]) { $this->published = $publish; } } } $this->setError(''); return true; }
/** * Get needed connection from database-controller * * @return null|PDO - PDO object * @throws Exception */ protected final function getDatabase() { return $this->_db->getDatabase($this->_connectionName); }
/** * Database object constructor * * @access public * @param array List of options used to configure the connection * @since 1.5 * @see bDatabase */ 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; // Unlike mysql_connect(), mysqli_connect() takes the port and socket // as separate arguments. Therefore, we have to extract them from the // host string. $port = NULL; $socket = NULL; $targetSlot = substr(strstr($host, ":"), 1); if (!empty($targetSlot)) { // Get the port number or socket name if (is_numeric($targetSlot)) { $port = $targetSlot; } else { $socket = $targetSlot; } // Extract the host name only $host = substr($host, 0, strlen($host) - (strlen($targetSlot) + 1)); // This will take care of the following notation: ":3306" if ($host == '') { $host = 'localhost'; } } // perform a number of fatality checks, then return gracefully if (!function_exists('mysqli_connect')) { $this->_errorNum = 1; $this->_errorMsg = 'The MySQL adapter "mysqli" is not available.'; return; } // connect to the server if (!($this->_resource = @mysqli_connect($host, $user, $password, NULL, $port, $socket))) { $this->_errorNum = 2; $this->_errorMsg = 'Could not connect to MySQL'; return; } // finalize initialization parent::__construct($options); // select the database if ($select) { $this->select($database); } }