Rev 1086 | Rev 1130 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1086 | Rev 1116 | ||
---|---|---|---|
Line 28... | Line 28... | ||
28 | 28 | ||
29 | protected $stmt = null; |
29 | protected $stmt = null; |
30 | protected $nCols = null; |
30 | protected $nCols = null; |
31 | protected $no_resultset = null; |
31 | protected $no_resultset = null; |
32 | 32 | ||
- | 33 | /** |
|
- | 34 | * @param $stmt |
|
- | 35 | */ |
|
33 | public function __construct($stmt) { |
36 | public function __construct($stmt) { |
34 | $metadata = mysqli_stmt_result_metadata($stmt); |
37 | $metadata = mysqli_stmt_result_metadata($stmt); |
35 | 38 | ||
36 | $this->no_resultset = is_bool($metadata); |
39 | $this->no_resultset = is_bool($metadata); |
37 | 40 | ||
Line 43... | Line 46... | ||
43 | 46 | ||
44 | $this->stmt->store_result(); |
47 | $this->stmt->store_result(); |
45 | } |
48 | } |
46 | } |
49 | } |
47 | 50 | ||
- | 51 | /** |
|
- | 52 | * @return bool |
|
- | 53 | */ |
|
48 | public function containsResultSet(): bool { |
54 | public function containsResultSet(): bool { |
49 | return !$this->no_resultset; |
55 | return !$this->no_resultset; |
50 | } |
56 | } |
51 | 57 | ||
- | 58 | /** |
|
- | 59 | * @return int |
|
- | 60 | * @throws OIDplusException |
|
- | 61 | */ |
|
52 | public function num_rows(): int { |
62 | public function num_rows(): int { |
53 | if ($this->no_resultset) throw new OIDplusException(_L('The query has returned no result set (i.e. it was not a SELECT query)')); |
63 | if ($this->no_resultset) throw new OIDplusException(_L('The query has returned no result set (i.e. it was not a SELECT query)')); |
54 | 64 | ||
55 | //$this->stmt->store_result(); |
65 | //$this->stmt->store_result(); |
56 | return $this->stmt->num_rows; |
66 | return $this->stmt->num_rows; |
57 | } |
67 | } |
58 | 68 | ||
- | 69 | /** |
|
- | 70 | * @return array|null |
|
- | 71 | * @throws OIDplusException |
|
- | 72 | */ |
|
59 | public function fetch_array()/*: ?array*/ { |
73 | public function fetch_array()/*: ?array*/ { |
60 | if ($this->no_resultset) throw new OIDplusException(_L('The query has returned no result set (i.e. it was not a SELECT query)')); |
74 | if ($this->no_resultset) throw new OIDplusException(_L('The query has returned no result set (i.e. it was not a SELECT query)')); |
61 | 75 | ||
62 | // https://stackoverflow.com/questions/10752815/mysqli-get-result-alternative , modified |
76 | // https://stackoverflow.com/questions/10752815/mysqli-get-result-alternative , modified |
63 | $stmt = $this->stmt; |
77 | $stmt = $this->stmt; |
Line 94... | Line 108... | ||
94 | 108 | ||
95 | // Return the array we built. |
109 | // Return the array we built. |
96 | return $ret; |
110 | return $ret; |
97 | } |
111 | } |
98 | 112 | ||
- | 113 | /** |
|
- | 114 | * @return \stdClass|null |
|
- | 115 | * @throws OIDplusConfigInitializationException |
|
- | 116 | * @throws OIDplusException |
|
- | 117 | */ |
|
99 | public function fetch_object()/*: ?object*/ { |
118 | public function fetch_object()/*: ?object*/ { |
100 | if ($this->no_resultset) throw new OIDplusConfigInitializationException(_L('The query has returned no result set (i.e. it was not a SELECT query)')); |
119 | if ($this->no_resultset) throw new OIDplusConfigInitializationException(_L('The query has returned no result set (i.e. it was not a SELECT query)')); |
101 | 120 | ||
102 | $ary = $this->fetch_array(); |
121 | $ary = $this->fetch_array(); |
103 | if (!$ary) return null; |
122 | if (!$ary) return null; |