lithium\data\source\database\adapter\Sqlite3::connect PHP Method

connect() public method

Connects to the database by constructing DSN string and creating a PDO intance using the parent class. Will set specific options on the connection as provided.
public connect ( ) : boolean
return boolean Returns `true` if a database connection could be established, otherwise `false`.
    public function connect()
    {
        if (!$this->_config['database']) {
            throw new ConfigException('No Database configured');
        }
        if (empty($this->_config['dsn'])) {
            $this->_config['dsn'] = sprintf("sqlite:%s", $this->_config['database']);
        }
        return parent::connect();
    }

Usage Example

Esempio n. 1
0
 /**
  * Tests that this adapter can connect to the database, and that the status is properly
  * persisted.
  *
  * @return void
  */
 public function testDatabaseConnection()
 {
     $db = new Sqlite3(array('autoConnect' => false) + $this->_dbConfig);
     $this->assertTrue($db->connect());
     $this->assertTrue($db->isConnected());
     $this->assertTrue($db->disconnect());
     $this->assertFalse($db->isConnected());
 }