From f2564794bfe3688e0177e9cb35deab6ab6e0fe7d Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 14 Sep 2007 01:23:36 +0000 Subject: [PATCH] pkrenn: Basic PDO (PHP Database Object) class, including the connection strings. Other functions need to be ported from MySQLDatabase.php into PDO syntax. (merged from branches/gsoc) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@41702 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/PDODatabase.php | 149 +++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 core/model/PDODatabase.php diff --git a/core/model/PDODatabase.php b/core/model/PDODatabase.php new file mode 100644 index 000000000..005444615 --- /dev/null +++ b/core/model/PDODatabase.php @@ -0,0 +1,149 @@ +
  • database: The database to connect with
  • + *
  • server: The server, eg, localhost
  • + *
  • username: The username to log on with
  • + *
  • password: The password to log on with
  • + *
  • database: The database to connect to
  • + */ + public function __construct($parameters) { + switch ($parameters['database']) { + case "MySQL": + $connect = 'mysql:host=' . $parameters['server'] . ';dbname=' . $parameters['database']; + break; + case "PostgreSQL": + $connect = 'pgsql:host=' . $parameters['server'] . ';port=5432;dbname=' . $parameters['database']; + break; + case "MSSQL": + $connect = 'mssql:host=' . $parameters['server'] . ';dbname=' . $parameters['database']; + break; + default: $this->databaseError("Database not available"); + } + $this->dbConn = new PDO($connect, $parameters['username'], $parameters['password']); + $this->database = $parameters['database']; + if(!$this->dbConn) $this->databaseError("Could connect to MySQL database"); + parent::__construct(); + } + + /** + * Returns true if this database supports collations + */ + public function supportsCollations() { + } + + //private $mysqlVersion; + public function getVersion() { + } + + public function query($sql, $errorLevel = E_USER_ERROR) { + } + public function getGeneratedID() { + } + public function getNextID($table) { + } + public function isActive() { + } + public function createDatabase() { + } + /** + * Create a new table with an integer primary key called ID. + */ + public function createTable($tableName) { + } + /** + * Create a new table with an integer primary key called ID. + */ + public function renameTable($oldTableName, $newTableName) { + } + + /** + * Checks a table's integrity and repairs it if necessary + */ + public function checkAndRepairTable($tableName) { + } + protected function runTableCheckCommand($sql) { + } + + /** + * Add the given field to the given table. + */ + public function createField($tableName, $fieldName, $fieldSpec) { + } + /** + * Change the database type of the given field + */ + public function alterField($tableName, $fieldName, $fieldSpec) { + } + + /** + * Get a list of all the fields for the given table. + * Returns a map of field name => field spec + */ + public function fieldList($table) { + } + + public function createIndex($tableName, $indexName, $indexSpec) { + } + public function alterIndex($tableName, $indexName, $indexSpec) { + } + public function indexList($table) { + } + + + /** + * Returns a list of all the tables in the column. + * Table names will all be in lowercase + */ + public function tableList() { + } + + /** + * Return the number of rows affected by the previous operation. + */ + public function affectedRows() { + } +} + +/** + * A result-set from a MySQL database. + */ +class MySQLQuery extends Query { + private $database; + private $handle; + + /** + * Hook the result-set given into a Query class, suitable for use by sapphire. + * @param database The database object that created this query. + * @param handle the internal mysql handle that is points to the resultset. + */ + public function __construct(MySQLDatabase $database, $handle) { + $this->database = $database; + $this->handle = $handle; + parent::__construct(); + } + + public function __destroy() { + } + + public function seek($row) { + } + public function numRecords() { + } + + public function nextRecord() { + } +} + +?> \ No newline at end of file