Core/src/Database/drivers/mysqli/mysqli_result.php

183 lines
4.1 KiB
PHP

<?php
/**
* FuzeWorks.
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author TechFuze
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
*
* @link http://techfuze.net/fuzeworks
* @since Version 0.0.1
*
* @version Version 1.0.0
*/
/**
* MySQLi Result Class
*
* This class extends the parent result class: FW_DB_result
*
* Converted from CodeIgniter.
*
* @package FuzeWorks
* @subpackage Drivers
* @category Database
* @author EllisLab Dev Team
* @link https://codeigniter.com/user_guide/database/
* @license http://opensource.org/licenses/MIT MIT License
*/
class FW_DB_mysqli_result extends FW_DB_result {
/**
* Number of rows in the result set
*
* @return int
*/
public function num_rows()
{
return is_int($this->num_rows)
? $this->num_rows
: $this->num_rows = $this->result_id->num_rows;
}
// --------------------------------------------------------------------
/**
* Number of fields in the result set
*
* @return int
*/
public function num_fields()
{
return $this->result_id->field_count;
}
// --------------------------------------------------------------------
/**
* Fetch Field Names
*
* Generates an array of column names
*
* @return array
*/
public function list_fields()
{
$field_names = array();
$this->result_id->field_seek(0);
while ($field = $this->result_id->fetch_field())
{
$field_names[] = $field->name;
}
return $field_names;
}
// --------------------------------------------------------------------
/**
* Field data
*
* Generates an array of objects containing field meta-data
*
* @return array
*/
public function field_data()
{
$retval = array();
$field_data = $this->result_id->fetch_fields();
for ($i = 0, $c = count($field_data); $i < $c; $i++)
{
$retval[$i] = new stdClass();
$retval[$i]->name = $field_data[$i]->name;
$retval[$i]->type = $field_data[$i]->type;
$retval[$i]->max_length = $field_data[$i]->max_length;
$retval[$i]->primary_key = (int) ($field_data[$i]->flags & 2);
$retval[$i]->default = $field_data[$i]->def;
}
return $retval;
}
// --------------------------------------------------------------------
/**
* Free the result
*
* @return void
*/
public function free_result()
{
if (is_object($this->result_id))
{
$this->result_id->free();
$this->result_id = FALSE;
}
}
// --------------------------------------------------------------------
/**
* Data Seek
*
* Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
* result set starts at zero.
*
* @param int $n
* @return bool
*/
public function data_seek($n = 0)
{
return $this->result_id->data_seek($n);
}
// --------------------------------------------------------------------
/**
* Result - associative array
*
* Returns the result set as an array
*
* @return array
*/
protected function _fetch_assoc()
{
return $this->result_id->fetch_assoc();
}
// --------------------------------------------------------------------
/**
* Result - object
*
* Returns the result set as an object
*
* @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
{
return $this->result_id->fetch_object($class_name);
}
}