mirror of
https://github.com/dg/dibi.git
synced 2025-08-04 13:17:58 +02:00
* added dibi::fetch, dibi::fetchAll, dibi::fetchSingle
* some bugs fixed
This commit is contained in:
@@ -260,6 +260,54 @@ class dibi extends NClass
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes SQL query and fetch result - Monostate for DibiConnection::query() & fetch()
|
||||||
|
*
|
||||||
|
* @param array|mixed one or more arguments
|
||||||
|
* @return array
|
||||||
|
* @throws DibiException
|
||||||
|
*/
|
||||||
|
public static function fetch($args)
|
||||||
|
{
|
||||||
|
if (!is_array($args)) $args = func_get_args();
|
||||||
|
|
||||||
|
return self::getConnection()->query($args)->fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes SQL query and fetch results - Monostate for DibiConnection::query() & fetchAll()
|
||||||
|
*
|
||||||
|
* @param array|mixed one or more arguments
|
||||||
|
* @return array
|
||||||
|
* @throws DibiException
|
||||||
|
*/
|
||||||
|
public static function fetchAll($args)
|
||||||
|
{
|
||||||
|
if (!is_array($args)) $args = func_get_args();
|
||||||
|
|
||||||
|
return self::getConnection()->query($args)->fetchAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes SQL query and fetch first column - Monostate for DibiConnection::query() & fetchSingle()
|
||||||
|
*
|
||||||
|
* @param array|mixed one or more arguments
|
||||||
|
* @return string
|
||||||
|
* @throws DibiException
|
||||||
|
*/
|
||||||
|
public static function fetchSingle($args)
|
||||||
|
{
|
||||||
|
if (!is_array($args)) $args = func_get_args();
|
||||||
|
|
||||||
|
return self::getConnection()->query($args)->fetchSingle();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query
|
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query
|
||||||
* Monostate for DibiConnection::insertId()
|
* Monostate for DibiConnection::insertId()
|
||||||
|
@@ -250,7 +250,7 @@ class DibiOdbcDriver extends NObject implements DibiDriverInterface
|
|||||||
*/
|
*/
|
||||||
public function fetch()
|
public function fetch()
|
||||||
{
|
{
|
||||||
return odbc_fetch_array($this->resultset, $this->row++);
|
return odbc_fetch_array($this->resultset, ++$this->row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -49,12 +49,6 @@ class DibiPdoDriver extends NObject implements DibiDriverInterface
|
|||||||
private $resultset;
|
private $resultset;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cursor
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
private $row = 0;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connects to a database
|
* Connects to a database
|
||||||
@@ -204,7 +198,7 @@ class DibiPdoDriver extends NObject implements DibiDriverInterface
|
|||||||
*/
|
*/
|
||||||
public function rowCount()
|
public function rowCount()
|
||||||
{
|
{
|
||||||
return $this->resultset->rowCount();
|
throw new DibiDatabaseException('Row count is not available for unbuffered queries');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -217,7 +211,7 @@ class DibiPdoDriver extends NObject implements DibiDriverInterface
|
|||||||
*/
|
*/
|
||||||
public function fetch()
|
public function fetch()
|
||||||
{
|
{
|
||||||
return $this->resultset->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT, $this->row++);
|
return $this->resultset->fetch(PDO::FETCH_ASSOC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -231,7 +225,7 @@ class DibiPdoDriver extends NObject implements DibiDriverInterface
|
|||||||
*/
|
*/
|
||||||
public function seek($row)
|
public function seek($row)
|
||||||
{
|
{
|
||||||
$this->row = $row;
|
throw new DibiDatabaseException('Cannot seek an unbuffered result set');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -23,21 +23,26 @@ product_id | title
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// fetch a single row
|
||||||
|
$row = dibi::fetch('SELECT title FROM [products]');
|
||||||
|
print_r($row); // Chair
|
||||||
|
echo '<hr>';
|
||||||
|
|
||||||
|
|
||||||
// fetch a single value
|
// fetch a single value
|
||||||
$res = dibi::query('SELECT [title] FROM [products]');
|
$value = dibi::fetchSingle('SELECT [title] FROM [products]');
|
||||||
$value = $res->fetchSingle();
|
|
||||||
print_r($value); // Chair
|
print_r($value); // Chair
|
||||||
echo '<hr>';
|
echo '<hr>';
|
||||||
|
|
||||||
|
|
||||||
// fetch complete result set
|
// fetch complete result set
|
||||||
$res = dibi::query('SELECT * FROM [products]');
|
$all = dibi::fetchAll('SELECT * FROM [products]');
|
||||||
$all = $res->fetchAll();
|
|
||||||
print_r($all);
|
print_r($all);
|
||||||
echo '<hr>';
|
echo '<hr>';
|
||||||
|
|
||||||
|
|
||||||
// fetch complete result set like association array
|
// fetch complete result set like association array
|
||||||
|
$res = dibi::query('SELECT * FROM [products]');
|
||||||
$assoc = $res->fetchAssoc('title'); // key
|
$assoc = $res->fetchAssoc('title'); // key
|
||||||
print_r($assoc);
|
print_r($assoc);
|
||||||
echo '<hr>';
|
echo '<hr>';
|
||||||
|
Binary file not shown.
Reference in New Issue
Block a user