Rev 277 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
277 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
5 | * Copyright 2019 Daniel Marschall, ViaThinkSoft |
||
6 | * |
||
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
8 | * you may not use this file except in compliance with the License. |
||
9 | * You may obtain a copy of the License at |
||
10 | * |
||
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
12 | * |
||
13 | * Unless required by applicable law or agreed to in writing, software |
||
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
16 | * See the License for the specific language governing permissions and |
||
17 | * limitations under the License. |
||
18 | */ |
||
19 | |||
20 | class OIDplusQueryResultPDO extends OIDplusQueryResult { |
||
21 | protected $no_resultset; |
||
22 | protected $res; |
||
23 | |||
24 | public function __construct($res) { |
||
25 | $this->no_resultset = is_bool($res); |
||
26 | |||
27 | if (!$this->no_resultset) { |
||
28 | $this->res = $res; |
||
29 | } |
||
30 | } |
||
31 | |||
32 | public function __destruct() { |
||
33 | if ($this->res) $this->res->closeCursor(); |
||
34 | } |
||
35 | |||
36 | public function containsResultSet(): bool { |
||
37 | return !$this->no_resultset; |
||
38 | } |
||
39 | |||
40 | public function num_rows(): int { |
||
360 | daniel-mar | 41 | if ($this->no_resultset) throw new OIDplusException(_L('The query has returned no result set (i.e. it was not a SELECT query)')); |
277 | daniel-mar | 42 | return $this->res->rowCount(); |
43 | } |
||
44 | |||
45 | public function fetch_array()/*: ?array*/ { |
||
360 | daniel-mar | 46 | if ($this->no_resultset) throw new OIDplusException(_L('The query has returned no result set (i.e. it was not a SELECT query)')); |
277 | daniel-mar | 47 | $ret = $this->res->fetch(PDO::FETCH_ASSOC); |
48 | if ($ret === false) $ret = null; |
||
49 | return $ret; |
||
50 | } |
||
51 | |||
52 | public function fetch_object()/*: ?object*/ { |
||
360 | daniel-mar | 53 | if ($this->no_resultset) throw new OIDplusException(_L('The query has returned no result set (i.e. it was not a SELECT query)')); |
277 | daniel-mar | 54 | $ret = $this->res->fetch(PDO::FETCH_OBJ); |
55 | if ($ret === false) $ret = null; |
||
56 | return $ret; |
||
57 | } |
||
360 | daniel-mar | 58 | } |