You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.1 KiB

<?php
/**
* @copyright NetMonsters <team@netmonsters.ru>
* @link http://netmonsters.ru
* @package Majestic
* @subpackage db
* @since 2010-02-19
* @version SVN: $Id$
* @filesource $URL$
*/
/**
* @property MySQLiDriver $driver
* @property MySQLi_Result $result
*/
class MySQLiStatement extends DbStatement
{
public function fetch($style = Db::FETCH_OBJ)
{
if (! $this->result) {
return false;
}
$row = false;
switch ($style) {
case Db::FETCH_OBJ:
$row = $this->result->fetch_object();
break;
case Db::FETCH_NUM:
$row = $this->result->fetch_array(MYSQLI_NUM);
break;
case Db::FETCH_ASSOC:
$row = $this->result->fetch_assoc();
break;
case Db::FETCH_BOTH:
$row = $this->result->fetch_array(MYSQLI_BOTH);
break;
default:
throw new Exception('Invalid fetch mode "' . $style . '" specified');
}
return $row;
}
/**
* @param string $class
*/
public function fetchObject($class = 'stdClass')
{
return $this->result->fetch_object($class);
}
public function close()
{
if ($this->result !== null) {
$this->result->close();
$this->result = null;
}
}
public function affectedRows()
{
return $this->driver->getConnection()->affected_rows;
}
public function numRows()
{
if ($this->result) {
return $this->result->num_rows;
}
return false;
}
protected function driverExecute($sql)
{
/**
* @var MySQLi
*/
$mysqli = $this->driver->getConnection();
$result = $mysqli->query($sql);
if ($result === false) {
throw new Exception($mysqli->error, $mysqli->errno);
}
if ($result instanceof MySQLi_Result) {
$this->result = $result;
}
return true;
}
}