Esempio n. 1
0
 static function baseDB($dsn, $options = array())
 {
     $opts = $options + array('username' => NULL, 'password' => NULL, 'db params' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
     if ($dsn instanceof PDO) {
         self::$con = $dsn;
         return;
     }
     self::$con = new PDO($dsn, $opts['username'], $opts['password'], $opts['db params']);
 }
Esempio n. 2
0
 /**
  * Create a new database instance for all QueryPath objects to share.
  *
  * This method need be called only once. From there, other QPDB instances
  * will (by default) share the same database instance.
  *
  * Normally, a DSN should be passed in. Username, password, and db params
  * are all passed in using the options array.
  *
  * On rare occasions, it may be more fitting to pass in an existing database
  * connection (which must be a {@link PDO} object). In such cases, the $dsn
  * parameter can take a PDO object instead of a DSN string. The standard options
  * will be ignored, though.
  *
  * <b>Warning:</b> If you pass in a PDO object that is configured to NOT throw
  * exceptions, you will need to handle error checking differently.
  *
  * <b>Remember to always use {@link QPDB::doneWithQuery()} when you are done
  * with a query. It gives PDO a chance to clean up open connections that may
  * prevent other instances from accessing or modifying data.</b>
  *
  * @param string $dsn
  *  The DSN of the database to connect to. You can also pass in a PDO object, which
  *  will set the QPDB object's database to the one passed in.
  * @param array $options
  *  An array of configuration options. The following options are currently supported:
  *  - username => (string)
  *  - password => (string)
  *  - db params => (array) These will be passed into the new PDO object.
  *    See the PDO documentation for a list of options. By default, the
  *    only flag set is {@link PDO::ATTR_ERRMODE}, which is set to 
  *    {@link PDO::ERRMODE_EXCEPTION}.
  * @throws PDOException
  *  An exception may be thrown if the connection cannot be made.
  */
 static function baseDB($dsn, $options = array())
 {
     $opts = $options + array('username' => NULL, 'password' => NULL, 'db params' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
     // Allow this to handle the case where an outside
     // connection does the initialization.
     if ($dsn instanceof PDO) {
         self::$con = $dsn;
         return;
     }
     self::$con = new PDO($dsn, $opts['username'], $opts['password'], $opts['db params']);
 }