コード例 #1
0
 /**
  * The options are:
  * - debug_level: level of debug if it's not specified it's set by debugObject to DEBUG_DEFAULT_LEVEL
  * - dsn: the Data Source Name to connect to a database through PEAR::MDB2 {@link http://pear.php.net/manual/en/package.database.mdb2.intro-dsn.php}.
  *   The DSN must be provided as an associative array or as a string.
  *   The array format is preferred, since it doesn't require a further parsing step (see the {@link http://pear.php.net/manual/en/package.database.mdb2.intro-connect.php Connecting
  *   chapter} for an example). The string format of the supplied DSN is in its fullest form:
  *   phptype(dbsyntax)://username:password@protocol+hostspec/database?option=value 
  *   Examples:
  *   $dsn =  'mysqli://*****:*****@localhost/masterdb'
  *   $dsn = array(
  *		'phptype'  => 'mysqli',
  *		'username' => 'themaster',
  *		'password' => 'thepowerofthepower',
  *		'hostspec' => 'localhost',
  *		'database' => 'masterdb'
  *	); 
  * - mdb2_options: can contain runtime configuration settings for the MDB2 package (see the {@link http://pear.php.net/manual/en/package.database.mdb2.intro-connect.php Connecting} for more details).
  * - table: the name of the table where debug logs are stored. 
  *
  * @param array $options
  * @throws BadMethodCallException
  * @throws exceptions
  */
 public function __construct($options = null)
 {
     $this->_dsn = isset($options['dsn']) ? $options['dsn'] : DEBUG_DEFAULT_MYSQL_DSN;
     $this->_table = isset($options['table']) ? $options['table'] : DEBUG_DEFAULT_MYSQL_TABLE;
     $this->_mdb2_options = isset($options['mdb2_options']) ? $options['mdb2_options'] : array();
     parent::__construct($options);
     $this->_mdb2 =& MDB2::factory($this->_dsn, $this->_mdb2_options);
     if (PEAR::isError($this->_mdb2)) {
         throw new exceptions($this->_mdb2->getMessage(), $this->_mdb2->getCode());
     }
 }
コード例 #2
0
ファイル: Mdb2Connection.php プロジェクト: Trideon/gigolo
 public function Connect()
 {
     if ($this->_connected && !is_null($this->_db)) {
         return;
     }
     $dsn = array('phptype' => $this->_dbType, 'username' => $this->_dbUser, 'password' => $this->_dbPassword, 'hostspec' => $this->_hostSpec, 'database' => $this->_dbName);
     $options = array('debug' => 0, 'portability' => MDB2_PORTABILITY_ALL, 'persistent' => true);
     $this->_db =& MDB2::connect($dsn, $options);
     if (MDB2::isError($this->_db)) {
         // If there is an error, print to browser, print to logfile and kill app
         throw new Exception("Error connecting to database\nError: " . $this->_db->getMessage() . "\nDebug: " . $this->_db->getDebugInfo());
         // TODO: LOG
     }
     $this->_db->setFetchMode(MDB2_FETCHMODE_ASSOC);
     // Set fetch mode to return associatve array
     $this->_connected = true;
 }