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)
|
|
|
|
*/
|
2016-09-09 08:43:05 +02:00
|
|
|
class MySQLQuery extends 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) {
|
2016-08-19 00:51:35 +02:00
|
|
|
if (is_object($this->handle)) {
|
|
|
|
return $this->handle->data_seek($row);
|
|
|
|
}
|
|
|
|
return null;
|
2013-06-21 00:32:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function numRecords() {
|
2016-08-19 00:51:35 +02:00
|
|
|
if (is_object($this->handle)) {
|
|
|
|
return $this->handle->num_rows;
|
|
|
|
}
|
|
|
|
return null;
|
2013-06-21 00:32:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function nextRecord() {
|
|
|
|
if (is_object($this->handle) && ($data = $this->handle->fetch_assoc())) {
|
|
|
|
return $data;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|