Created
February 14, 2013 12:48
-
-
Save ThaDafinser/4952542 to your computer and use it in GitHub Desktop.
Zend\Db\Adapter\Adapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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