×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Сергей Шевченко
Added: Apr 21, 2017 10:05 AM
Modified: May 23, 2017 3:59 PM
Views: 36
Tags: sql
  1. /**
  2.      * @param EntityManager $connect
  3.      * @param $sql
  4.      * @param array $params
  5.      * @param bool $return
  6.      *
  7.      * @return array
  8.      */
  9.     private function takeSQL(EntityManager $connect, $sql, array $params = [], $return = true)
  10.     {
  11.         /** @var PDOConnection $connection */
  12.         $connection = $connect->getConnection();
  13.         $statement = $connection->prepare($sql);
  14.  
  15.         if (count($params) > 0) {
  16.             foreach ($params as $key => $value) {
  17.                 $statement->bindValue($key, $value);
  18.             }
  19.         }
  20.  
  21.         $statement->execute();
  22.  
  23.         if ($return) {
  24.             return $statement->fetchAll();
  25.         }
  26.     }