コード例 #1
0
ファイル: mysql.php プロジェクト: Jonathonbyrd/5TwentyCMS
 /**
  * Database object constructor
  *
  * @access	public
  * @param	array	List of options used to configure the connection
  * @since	1.5
  * @see		FiveDatabase
  */
 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);
     }
 }
コード例 #2
0
ファイル: table.php プロジェクト: Jonathonbyrd/5TwentyCMS
 /**
  * Generic save function
  *
  * @access	public
  * @param	array	Source array for binding to class vars
  * @param	string	Filter for the order updating
  * @param	mixed	An array or space separated list of fields not to bind
  * @returns TRUE if completely successful, FALSE if partially or not succesful.
  */
 function save($source, $order_filter = '', $ignore = '')
 {
     if (!$this->bind($source, $ignore)) {
         return false;
     }
     if (!$this->check()) {
         return false;
     }
     if (!$this->store()) {
         return false;
     }
     if ($order_filter) {
         $filter_value = $this->{$order_filter};
         $this->reorder($order_filter ? $this->_db->nameQuote($order_filter) . ' = ' . $this->_db->Quote($filter_value) : '');
     }
     $this->setError('');
     return true;
 }
コード例 #3
0
ファイル: mysqli.php プロジェクト: Jonathonbyrd/5TwentyCMS
 /**
  * Database object constructor
  *
  * @access	public
  * @param	array	List of options used to configure the connection
  * @since	1.5
  * @see		FiveDatabase
  */
 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);
     }
 }
コード例 #4
0
ファイル: factory.php プロジェクト: Jonathonbyrd/5TwentyCMS
 /**
  * Create an database object
  *
  * @access private
  * @param string $database	The name of the database connection to use
  * @return object FiveDatabase
  * @since 1.5
  */
 function &_createDBO($database)
 {
     $host = config("database.{$database}.host");
     $user = config("database.{$database}.username");
     $password = config("database.{$database}.password");
     $name = config("database.{$database}.name");
     $prefix = config("database.{$database}.prefix");
     $driver = config("database.{$database}.driver");
     $debug = config("base.debug");
     $options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $name, 'prefix' => $prefix);
     $db =& FiveDatabase::getInstance($options);
     if (!is_object($db)) {
         header('HTTP/1.1 500 Internal Server Error');
         exit('Database Error: ' . $db);
     }
     if ($db->getErrorNum() > 0) {
         trigger_error('FiveDatabase::getInstance: Could not connect to database <br />' . 'library:' . $db->getErrorNum() . ' - ' . $db->getErrorMsg(), E_USER_ERROR);
     }
     $db->debug($debug);
     return $db;
 }