Blame view

framework/model/MySQLQuery.php 1.29 KB
0084d336   Administrator   Importers CRUD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
  <?php
  
  /**
   * A result-set from a MySQL database.
   *
   * @package framework
   * @subpackage model
   */
  class MySQLQuery extends SS_Query {
  
  	/**
  	 * The MySQLDatabase object that created this result set.
  	 * @var MySQLDatabase
  	 */
  	protected $database;
  
  	/**
  	 * The internal MySQL handle that points to the result set.
  	 * @var resource
  	 */
  	protected $handle;
  
  	/**
  	 * Hook the result-set given into a Query class, suitable for use by 
  	 * SilverStripe.
  	 *
  	 * @param database $database The database object that created this query.
  	 * @param handle $handle the internal mysql handle that is points to the resultset.
  	 */
  	public function __construct(MySQLDatabase $database, $handle) {
  		$this->database = $database;
  		$this->handle = $handle;
  	}
  
  	public function __destruct() {
  		if(is_object($this->handle)) {
  			$this->handle->free();
  		}
  	}
  	
  	/**
  	 * {@inheritdoc}
  	 */
  	public function seek($row) {
  		if(is_object($this->handle)) {
  			return $this->handle->data_seek($row);
  		}
  	}
  	
  	/**
  	 * {@inheritdoc}
  	 */
  	public function numRecords() {
  		if(is_object($this->handle)) {
  			return $this->handle->num_rows;
  		}
  	}
  
  	/**
  	 * {@inheritdoc}
  	 */
  	public function nextRecord() {
  		if(is_object($this->handle) && ($data = $this->handle->fetch_assoc())) {
  			return $data;
  		} else {
  			return false;
  		}
  	}
  }