connect() public méthode

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
Résultat boolean Returns `true` if a database connection could be established, otherwise `false`.
Exemple #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 MySql(array('autoConnect' => false) + $this->_dbConfig);
     $this->assertTrue($db->connect());
     $this->assertTrue($db->isConnected());
     $this->assertTrue($db->disconnect());
     $this->assertFalse($db->isConnected());
 }
Exemple #2
0
 /**
  * Tests that this adapter can connect to the database, and that the status is properly
  * persisted.
  *
  * @return void
  */
 public function testDatabaseConnection()
 {
     $db = new MySql(array('autoConnect' => false) + $this->_dbConfig);
     $this->assertTrue($db->connect());
     $this->assertTrue($db->isConnected());
     $this->assertTrue($db->disconnect());
     $this->assertFalse($db->isConnected());
     $db = new MySQL(array('autoConnect' => false, 'encoding' => NULL, 'persistent' => false, 'host' => 'localhost:3306', 'login' => 'garbage', 'password' => '', 'database' => 'garbage', 'init' => true) + $this->_dbConfig);
     $this->assertFalse($db->connect());
     $this->assertFalse($db->isConnected());
     $this->assertTrue($db->disconnect());
     $this->assertFalse($db->isConnected());
 }