silverstripe-framework/model/connect/MySQLQuery.php
Damian Mooyman d8e9af8af8 API New Database abstraction layer. Ticket #7429
Database abstraction broken up into controller, connector, query builder, and schema manager, each independently configurable via YAML / Injector
Creation of new DBQueryGenerator for database specific generation of SQL
Support for parameterised queries, move of code base to use these over escaped conditions
Refactor of SQLQuery into separate query classes for each of INSERT UPDATE DELETE and SELECT
Support for PDO
Installation process upgraded to use new ORM
SS_DatabaseException created to handle database errors, maintaining details of raw sql and parameter details for user code designed interested in that data.
Renamed DB static methods to conform correctly to naming conventions (e.g. DB::getConn -> DB::get_conn)
3.2 upgrade docs
Performance Optimisation and simplification of code to use more concise API
API Ability for database adapters to register extensions to ConfigureFromEnv.php
2014-07-09 18:04:05 +12:00

67 lines
1.6 KiB
PHP

<?php
/**
* A result-set from a MySQL database (using MySQLiConnector)
*
* @package framework
* @subpackage model
*/
class MySQLQuery extends SS_Query {
/**
* The MySQLiConnector object that created this result set.
*
* @var MySQLiConnector
*/
protected $database;
/**
* The internal MySQL handle that points to the result set.
*
* @var mysqli_result
*/
protected $handle;
/**
* The related mysqli statement object if generated using a prepared query
*
* @var mysqli_stmt
*/
protected $statement;
/**
* Hook the result-set given into a Query class, suitable for use by SilverStripe.
* @param MySQLDatabase $database The database object that created this query.
* @param mysqli_result $handle the internal mysql handle that is points to the resultset.
* @param mysqli_stmt $statement The related statement, if present
*/
public function __construct(MySQLiConnector $database, $handle = null, $statement = null) {
$this->database = $database;
$this->handle = $handle;
$this->statement = $statement;
}
public function __destruct() {
if (is_object($this->handle)) $this->handle->free();
// Don't close statement as these may be re-used across the life of this request
// if (is_object($this->statement)) $this->statement->close();
}
public function seek($row) {
if (is_object($this->handle)) return $this->handle->data_seek($row);
}
public function numRecords() {
if (is_object($this->handle)) return $this->handle->num_rows;
}
public function nextRecord() {
if (is_object($this->handle) && ($data = $this->handle->fetch_assoc())) {
return $data;
} else {
return false;
}
}
}