3 * A database result class
5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.mxchange.org
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class DatabaseResult extends BaseFrameworkSystem {
26 * Current position in array
28 private $currentPos = -1;
33 private $currentRow = null;
38 private $resultArray = array();
41 * Protected constructor
45 protected function __construct () {
46 // Call parent constructor
47 parent::__construct(__CLASS__);
49 // Set part description
50 $this->setObjectDescription("Database result");
52 // Create unique ID number
53 $this->generateUniqueId();
56 $this->removeNumberFormaters();
57 $this->removeSystemArray();
61 * Creates an instance of this result by a provided result array
63 * @param $resultArray The array holding the result from query
64 * @return $resultInstance An instance of this class
66 public final static function createDatabaseResult (array $resultArray) {
68 $resultInstance = new DatabaseResult();
70 // Set the result array
71 $resultInstance->setResultArray($resultArray);
73 // Return the instance
74 return $resultInstance;
78 * Setter for result array
80 * @param $resultArray The array holding the result from query
83 protected final function setResultArray (array $resultArray) {
84 $this->resultArray = $resultArray;
88 * "Iterator" method next() to advance to the next valid entry. This method
89 * does also check if the result is invalid
91 * @return $nextValid Wether the next entry is valid
93 public function next () {
94 // Default is not valid
97 // Is the result valid?
98 if ($this->resultArray['status'] === "ok") {
99 // The status is fine so let's have a look for the next entry
100 if (isset($this->resultArray['rows'][($this->currentPos + 1)])) {
101 // Next entry found, so count one up and cache it
103 $this->currentRow = $this->resultArray['rows'][$this->currentPos];