Browse Source

rollback previous revision

git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/trunk@88 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
master
akulikov 16 years ago
parent
commit
7754a67a07
  1. 50
      classes/DBConnector.class.php
  2. 34
      classes/Model.class.php
  3. 8
      classes/pg_DBConnector.class.php

50
classes/DBConnector.class.php

@ -13,15 +13,6 @@
*/
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 public $queries = array();
@ -87,51 +78,12 @@ class DBConnector
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)
{
return mysqli_num_rows($result);
}
static public function affectedRows($handler, $result)
static public function affectedRows($handler)
{
return mysqli_affected_rows($handler);
}

34
classes/Model.class.php

@ -61,9 +61,9 @@ abstract class Model
return new ModelSelectResult($res);
case 'insert':
case 'replac':
return new ModelInsertResult($this->handler, $res); //$res for postgreSQL
return new ModelInsertResult($this->handler);
default:
return new ModelChangeResult($this->handler, $res); //$res for postgreSQL
return new ModelChangeResult($this->handler);
}
}
@ -183,28 +183,6 @@ class ModelSelectResult extends ModelResult
return $array;
}
/**
* Fetches all SQL result rows as an array of key-value pairs.
*
* The first column is the key, the second column is the
* value.
*
* @return array
*/
public function fetchPairs()
{
if (!method_exists('DBConnector', 'fetchArray')) {
throw new Exception('Method not implemented yet.');
}
$data = array();
while ($row = DBConnector::fetchArray($this->result, DBConnector::FETCH_NUM)) {
$data[$row[0]] = $row[1];
}
return $data;
}
function count()
{
return DBConnector::numRows($this->result);
@ -224,9 +202,9 @@ class ModelChangeResult extends ModelResult
{
public $affected;
function __construct($resource, $result)
function __construct($resource)
{
$this->affected = DBConnector::affectedRows($resource, $result);
$this->affected = DBConnector::affectedRows($resource);
}
function count()
@ -239,9 +217,9 @@ class ModelInsertResult extends ModelChangeResult
{
public $id;
function __construct($resource, $result)
function __construct($resource)
{
parent::__construct($resource, $result);
parent::__construct($resource);
$this->id = DBConnector::getId($resource);
}

8
classes/pg_DBConnector.class.php

@ -38,8 +38,8 @@ class DBConnector
return self::$handlers[$handler_name];
}
if (!$handler = pg_connect("host='".$db_settings['host']."' dbname='".$db_settings['database']."' user='".$db_settings['user']."' password='".$db_settings['password']."'")) {
throw new MJException('Can\'t connect to DB '.pg_last_error(), 2);
if (!$handler = pg_connect("host='".$db_settings['host']."' dbname='".$db_settings['database']."' user='".$db_settings['user'].'" password="'.$db_settings['password']."'")) {
throw new MJException('Can\'t connect to DB '.pg_last_error($handler), 2);
}
return self::$handlers[$handler_name] = $handler;
@ -82,9 +82,9 @@ class DBConnector
return pg_num_rows($result);
}
static public function affectedRows($handler, $result)
static public function affectedRows($handler)
{
return pg_affected_rows($result);
return pg_affected_rows($handler);
}
static public function getId($handler)

Loading…
Cancel
Save