Completed
Pull Request — master (#6435)
by Damian
08:35
created

MySQLQuery::keyedColumn()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 2
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\ORM\Connect;
4
5
/**
6
 * A result-set from a MySQL database (using MySQLiConnector)
7
 */
8
class MySQLQuery extends Query
9
{
10
11
    /**
12
     * The internal MySQL handle that points to the result set.
13
     * Select queries will have mysqli_result as a value.
14
     * Non-select queries will not
15
     *
16
     * @var mixed
17
     */
18
    protected $handle;
19
20
    /**
21
     * Hook the result-set given into a Query class, suitable for use by SilverStripe.
22
     *
23
     * @param MySQLiConnector $database The database object that created this query.
24
     * @param mixed $handle the internal mysql handle that is points to the resultset.
25
     * Non-mysqli_result values could be given for non-select queries (e.g. true)
26
     */
27
    public function __construct($database, $handle)
0 ignored issues
show
Unused Code introduced by
The parameter $database is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
28
    {
29
        $this->handle = $handle;
30
    }
31
32
    public function __destruct()
33
    {
34
        if (is_object($this->handle)) {
35
            $this->handle->free();
36
        }
37
    }
38
39
    public function seek($row)
40
    {
41
        if (is_object($this->handle)) {
42
            return $this->handle->data_seek($row);
43
        }
44
        return null;
45
    }
46
47
    public function numRecords()
48
    {
49
        if (is_object($this->handle)) {
50
            return $this->handle->num_rows;
51
        }
52
        return null;
53
    }
54
55
    public function nextRecord()
56
    {
57
        if (is_object($this->handle) && ($data = $this->handle->fetch_assoc())) {
58
            return $data;
59
        } else {
60
            return false;
61
        }
62
    }
63
}
64