phprs\ezsql\impls\ExecImpl::get PHP Метод

get() публичный статический Метод

public static get ( SqlConetxt $context, PDO $db, $dictAs = null, boolean $errExce = true ) : false | array
$context phprs\ezsql\SqlConetxt
$db PDO
$errExce boolean
Результат false | array
    public static function get($context, $db, $dictAs = null, $errExce = true)
    {
        if ($errExce) {
            $db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        }
        $db->setAttribute(\PDO::MYSQL_ATTR_FOUND_ROWS, true);
        $st = $db->prepare($context->sql);
        if ($st->execute($context->params)) {
            $res = $st->fetchAll(\PDO::FETCH_ASSOC);
            if ($dictAs) {
                $dict = [];
                foreach ($res as $i) {
                    $dict[$i[$dictAs]] = $i;
                }
                return $dict;
            }
            return $res;
        } else {
            return false;
        }
    }

Usage Example

Пример #1
0
 /**
  * Execute sql and get one response
  * @param $db
  * @param bool $errExce
  * @return mixed
  */
 public function getOnce($db, $errExce = true)
 {
     return ExecImpl::get($this->context, $db, false, $errExce)[0];
 }
ExecImpl