Created
March 3, 2016 13:47
-
-
Save estheban/3eae41271f6cf5f3180a to your computer and use it in GitHub Desktop.
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 Elcweb\LegacyBundle\Entity; | |
/** | |
* Class RawSQLTrait. | |
*/ | |
trait RawSQLTrait | |
{ | |
/** | |
* @param string $sql | |
* | |
* @return array | |
* | |
* @throws \Doctrine\DBAL\DBALException | |
*/ | |
private function fetchAll($sql) | |
{ | |
return $this->execute($sql)->fetchAll(); | |
} | |
/** | |
* @param string $sql | |
* | |
* @return mixed | |
*/ | |
private function execute($sql) | |
{ | |
$stmt = $this->getEntityManager()->getConnection()->prepare($sql); | |
$stmt->execute(); | |
return $stmt; | |
} | |
/** | |
* @param string $sql | |
* @param string $fieldName | |
* | |
* @return mixed | |
* | |
* @throws \Doctrine\DBAL\DBALException | |
*/ | |
private function fetchSingleField($sql, $fieldName) | |
{ | |
return $this->fetch($sql)[$fieldName]; | |
} | |
/** | |
* @param string $sql | |
* | |
* @return array | |
* | |
* @throws \Doctrine\DBAL\DBALException | |
*/ | |
private function fetch($sql) | |
{ | |
return $this->execute($sql)->fetch(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment