Subversion Repositories oidplus

Rev

Rev 360 | 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
511 daniel-mar 5
 * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
277 daniel-mar 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
 
511 daniel-mar 20
if (!defined('INSIDE_OIDPLUS')) die();
21
 
277 daniel-mar 22
class OIDplusQueryResultMySQL extends OIDplusQueryResult {
23
        protected $no_resultset;
24
        protected $res;
25
 
26
        public function __construct($res) {
27
                $this->no_resultset = is_bool($res);
28
 
29
                if (!$this->no_resultset) {
30
                        $this->res = $res;
31
                }
32
        }
33
 
34
        public function __destruct() {
35
                if ($this->res) $this->res->close();
36
        }
37
 
38
        public function containsResultSet(): bool {
39
                return !$this->no_resultset;
40
        }
41
 
42
        public function num_rows(): int {
360 daniel-mar 43
                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 44
                return $this->res->num_rows;
45
        }
46
 
47
        public function fetch_array()/*: ?array*/ {
360 daniel-mar 48
                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 49
                return $this->res->fetch_array(MYSQLI_ASSOC);
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
                return $this->res->fetch_object("stdClass");
55
        }
360 daniel-mar 56
}