PDO4You\PDO4You::selectRecords PHP Method

selectRecords() private static method

Method to query records in the database
private static selectRecords ( string $query, string $type, string $use, boolean $count = true ) : mixed
$query string SQL query
$type string Return type of the query
$use string Pseudonym of a connection instance
$count boolean OPTIONAL Counts the number of rows affected
return mixed
    private static function selectRecords($query, $type, $use, $count = true)
    {
        try {
            if (is_null($query)) {
                throw new \PDOException(self::$exception['no-argument-sql']);
            }
            if (!is_null($use)) {
                self::setInstance($use);
            }
            $result = null;
            $pdo = self::$instance;
            if (!$pdo instanceof \PDO) {
                throw new \PDOException(self::$exception['no-instance']);
            } else {
                if (Pagination::getPaging() == true) {
                    $pre = $pdo->prepare($query);
                    $pre->execute();
                    $result = $pre->fetchAll(\PDO::FETCH_ASSOC);
                    $query = Pagination::buildQuery($query, $result);
                }
                $pre = $pdo->prepare($query);
                if (!is_object($pre)) {
                    return;
                } else {
                    $pre->execute();
                }
                switch ($type) {
                    case 'num':
                        $result = $pre->fetchAll(\PDO::FETCH_NUM);
                        break;
                    case 'obj':
                        $result = $pre->fetchAll(\PDO::FETCH_OBJ);
                        break;
                    case 'all':
                        $result = $pre->fetchAll(\PDO::FETCH_BOTH);
                        break;
                    default:
                        $result = $pre->fetchAll(\PDO::FETCH_ASSOC);
                }
                if ($count) {
                    self::$rowCount = count($result);
                }
            }
        } catch (\PDOException $e) {
            self::stackTrace($e);
        }
        $pdo = null;
        return $result;
    }