|
@ -13,6 +13,15 @@ |
|
|
*/ |
|
|
*/ |
|
|
class DBConnector |
|
|
class DBConnector |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* PDO constant values. |
|
|
|
|
|
*/ |
|
|
|
|
|
const FETCH_ASSOC = 2; |
|
|
|
|
|
const FETCH_BOTH = 4; |
|
|
|
|
|
const FETCH_NUM = 3; |
|
|
|
|
|
const FETCH_OBJ = 5; |
|
|
|
|
|
|
|
|
static private $handlers = array(); |
|
|
static private $handlers = array(); |
|
|
static public $queries = array(); |
|
|
static public $queries = array(); |
|
|
|
|
|
|
|
@ -77,7 +86,46 @@ class DBConnector |
|
|
{ |
|
|
{ |
|
|
return $class_name ? mysqli_fetch_object($result, $class_name) : mysqli_fetch_object($result); |
|
|
return $class_name ? mysqli_fetch_object($result, $class_name) : mysqli_fetch_object($result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Fetches a row from the result set. |
|
|
|
|
|
* |
|
|
|
|
|
* @param mysqli_result $result |
|
|
|
|
|
* @param int $style OPTIONAL Fetch mode for this fetch operation. |
|
|
|
|
|
* @return mixed Array, object, or scalar depending on fetch mode. |
|
|
|
|
|
* @throws Exception |
|
|
|
|
|
*/ |
|
|
|
|
|
static public function fetchArray($result, $style = null) |
|
|
|
|
|
{ |
|
|
|
|
|
if (!$result) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($style === null) { |
|
|
|
|
|
$style = self::FETCH_ASSOC; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$row = false; |
|
|
|
|
|
switch ($style) { |
|
|
|
|
|
case self::FETCH_NUM: |
|
|
|
|
|
$row = mysqli_fetch_array($result, MYSQLI_NUM); |
|
|
|
|
|
break; |
|
|
|
|
|
case self::FETCH_ASSOC: |
|
|
|
|
|
$row = mysqli_fetch_array($result, MYSQLI_ASSOC); |
|
|
|
|
|
break; |
|
|
|
|
|
case self::FETCH_BOTH: |
|
|
|
|
|
$row = mysqli_fetch_array($result, MYSQLI_BOTH); |
|
|
|
|
|
break; |
|
|
|
|
|
case self::FETCH_OBJ: |
|
|
|
|
|
$row = mysqli_fetch_object($result, MYSQLI_BOTH); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
throw new Exception('Invalid fetch mode "' . $style . '" specified'); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
return $row; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
static public function numRows($result) |
|
|
static public function numRows($result) |
|
|
{ |
|
|
{ |
|
|
return mysqli_num_rows($result); |
|
|
return mysqli_num_rows($result); |
|
|