Skip to content

Instantly share code, notes, and snippets.

@ThaDafinser
Created February 14, 2013 12:48
Show Gist options
  • Save ThaDafinser/4952542 to your computer and use it in GitHub Desktop.
Save ThaDafinser/4952542 to your computer and use it in GitHub Desktop.
Zend\Db\Adapter\Adapter
<?php
namespace LispBase\Db\Adapter;
use Zend\Db\Adapter\Adapter as ZendAdapter;
use Zend\Db\Sql\Select;
class Adapter extends ZendAdapter
{
private function getSqlString ($sql)
{
if (is_string($sql)) {
return $sql;
}
if ($sql instanceof Select) {
return $sql->getSqlString(parent::getPlatform());
}
if (is_object($sql)) {
throw new \Exception('SQL object given: "' . get_class($sql) . '"');
} else {
throw new \Exception('SQL is not a supported type (string or object)...');
}
}
/**
* Fetch a single row
* Returns an array or false if nothing is found
*
* @param string|Select $sql
*
* @return array|false
*/
public function fetchRow ($sql)
{
$sql = $this->getSqlString($sql);
$statement = parent::query($sql);
$result = $statement->execute();
return $result->current();
}
/**
* Fetch all from the result
*
* @param string|Select $sql
*
* @return array
*/
public function fetchAll ($sql)
{
$sql = $this->getSqlString($sql);
$return = array();
$statement = parent::query($sql);
$result = $statement->execute();
foreach ($result as $row) {
$return[] = $row;
}
return $return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment