2013-06-21 00:32:08 +02:00
|
|
|
<?php
|
|
|
|
|
2016-06-15 06:03:16 +02:00
|
|
|
namespace SilverStripe\ORM\Connect;
|
|
|
|
|
2013-06-21 00:32:08 +02:00
|
|
|
/**
|
|
|
|
* A result-set from a MySQL database (using MySQLiConnector)
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2013-06-21 00:32:08 +02:00
|
|
|
* @package framework
|
2016-06-15 06:03:16 +02:00
|
|
|
* @subpackage orm
|
2013-06-21 00:32:08 +02:00
|
|
|
*/
|
|
|
|
class MySQLQuery extends SS_Query {
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-06-21 00:32:08 +02:00
|
|
|
/**
|
|
|
|
* The internal MySQL handle that points to the result set.
|
2015-04-29 07:32:57 +02:00
|
|
|
* Select queries will have mysqli_result as a value.
|
|
|
|
* Non-select queries will not
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2015-04-29 07:32:57 +02:00
|
|
|
* @var mixed
|
2013-06-21 00:32:08 +02:00
|
|
|
*/
|
|
|
|
protected $handle;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-06-21 00:32:08 +02:00
|
|
|
/**
|
|
|
|
* Hook the result-set given into a Query class, suitable for use by SilverStripe.
|
2015-04-29 07:32:57 +02:00
|
|
|
*
|
|
|
|
* @param MySQLiConnector $database The database object that created this query.
|
|
|
|
* @param mixed $handle the internal mysql handle that is points to the resultset.
|
|
|
|
* Non-mysqli_result values could be given for non-select queries (e.g. true)
|
2013-06-21 00:32:08 +02:00
|
|
|
*/
|
2015-04-29 07:32:57 +02:00
|
|
|
public function __construct($database, $handle) {
|
2013-06-21 00:32:08 +02:00
|
|
|
$this->handle = $handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __destruct() {
|
|
|
|
if (is_object($this->handle)) $this->handle->free();
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|