/** * @return DB_Adapter_Generic_DB */ protected function _getDB() { if (!$this->_dbtype) { throw new Exception('$_dbtype must be setted in derived class'); } if (empty(self::$_dsn)) { self::$_dsn = parse_ini_file(dirname(__FILE__) . '/../../../config/db-credentials.ini'); } if (empty(self::$_connections[$this->_dbtype])) { $con = DB_Adapter_Factory::connect(self::$_dsn[$this->_dbtype]); $con->setIdentPrefix('test_'); self::$_connections[$this->_dbtype] = $con; } return self::$_connections[$this->_dbtype]; }
public function testConnectionFailed() { $this->setExpectedException('DB_Adapter_Exception_ConnectionError'); $failed = DB_Adapter_Factory::connect('mysql://*****:*****@localhost/test?charset=utf8'); }
<?php error_reporting(E_ALL); ini_set('display_errors', 'On'); require_once '../../lib/config.php'; require_once 'DB/Adapter/Factory.php'; $dsn = parse_ini_file(dirname(__FILE__) . '/../../config/db-credentials.ini'); $DB = DB_Adapter_Factory::connect($dsn['postgresql']); $DB->setIdentPrefix('db_adapter_example_'); prepareMessageTable($DB); $messages = $DB->fetchAll("SELECT * FROM ?_guestbook_message ORDER BY created DESC"); if ($_POST) { addMessage($DB, $_POST); header('Location: ' . $_SERVER['REQUEST_URI']); } function prepareMessageTable($DB) { // $DB->query("DROP TABLE ?_guestbook_message"); @$DB->query("CREATE SEQUENCE example_guestbook_message_id_seq;"); @$DB->query("\n CREATE TABLE ?_guestbook_message (\n id int NOT NULL DEFAULT NEXTVAL('example_guestbook_message_id_seq'),\n author varchar(100) NOT NULL,\n text varchar(300) NOT NULL,\n created timestamp NOT NULL DEFAULT NOW()\n );\n "); } function addMessage($DB, $message) { if (!empty($message['text'])) { $DB->query("INSERT INTO ?_guestbook_message (?#) VALUES (?a)", array_keys($message), array_values($message)); } } require_once '_template.php';
protected function _connect() { $this->_DB = DB_Adapter_Factory::connect(TestConfig::$dsn[$this->_dbtype]); }
<?php error_reporting(E_ALL); ini_set('display_errors', 'On'); require_once '../../lib/config.php'; require_once 'DB/Adapter/Factory.php'; $dsn = parse_ini_file(dirname(__FILE__) . '/../../config/db-credentials.ini'); $DB = DB_Adapter_Factory::connect($dsn['mysql']); $DB->setIdentPrefix('db_adapter_example_'); prepareMessageTable($DB); $messages = $DB->fetchAll("SELECT * FROM ?_guestbook_message ORDER BY created DESC"); if ($_POST) { addMessage($DB, $_POST); header('Location: ' . $_SERVER['REQUEST_URI']); } function prepareMessageTable($DB) { // $DB->query("DROP TABLE ?_guestbook_message"); $DB->query("\n CREATE TABLE IF NOT EXISTS ?_guestbook_message (\n id int NOT NULL AUTO_INCREMENT PRIMARY KEY,\n author varchar(100) NOT NULL,\n text varchar(300) NOT NULL,\n created timestamp NOT NULL\n );\n "); } function addMessage($DB, $message) { if (!empty($message['text'])) { $DB->query("INSERT INTO ?_guestbook_message (?#) VALUES (?a)", array_keys($message), array_values($message)); } } require_once '_template.php';