public function setup() { /* The real, underlying connection... */ $settings = array('type' => 'sqlite'); AnewtDatabase::setup_connection($settings, 'non-cached'); /* ...and the caching connection */ $settings = array('type' => 'memcache', 'connection' => AnewtDatabase::get_connection('non-cached'), 'expiry' => 2, 'identifier' => 'test-id'); AnewtDatabase::setup_connection($settings, 'cached'); }
public function test_autoconnect() { $settings = array('type' => 'sqlite', 'autoconnect' => false); AnewtDatabase::setup_connection($settings, 'another-sqlite'); $connection = AnewtDatabase::get_connection('another-sqlite'); $this->assertFalse($connection->is_connected()); $connection->connect(); $this->assertTrue($connection->is_connected()); $connection->connect(); $this->assertTrue($connection->is_connected()); }
function test_two_connections() { $settings = array('type' => 'sqlite'); AnewtDatabase::setup_connection($settings); AnewtDatabase::setup_connection($settings, 'connection2'); $c2 = AnewtDatabase::get_connection('connection2'); $c1 = AnewtDatabase::get_connection(); $this->assertTrue($c1->is_connected()); $this->assertTrue($c2->is_connected()); $c1->disconnect(); $this->assertFalse($c1->is_connected()); $this->assertTrue($c2->is_connected()); }
public function setup() { AnewtDatabase::setup_connection(array('type' => 'sqlite')); $connection = AnewtDatabase::get_connection(); $connection->prepare_execute('CREATE TABLE Person ( id INTEGER PRIMARY KEY, name VARCHAR(255), age INTEGER, is_happy BOOLEAN )'); $pq = $connection->prepare('INSERT INTO Person (id, name, age, is_happy) VALUES (?int?, ?str?, ?int?, ?bool?)'); $pq->execute(1, 'A', 10, true); $pq->execute(2, 'B', 11, false); $pq->execute(3, 'C', 12, false); $pq->execute(4, 'D', 13, null); $pq->execute(5, 'E', 14, false); }
public function test_autoconnect() { $settings = array('type' => 'postgresql', 'hostname' => 'localhost', 'username' => 'anewt', 'password' => 'anewt', 'database' => 'anewt', 'autoconnect' => false); AnewtDatabase::setup_connection($settings, 'connection3'); $connection = AnewtDatabase::get_connection('connection3'); $this->assertFalse($connection->is_connected()); $connection->connect(); $this->assertTrue($connection->is_connected()); $connection->connect(); $this->assertTrue($connection->is_connected()); }