buildQuery() public static method

Builds a query and sets the number of records per page
See also: PDO4You::selectRecords()
public static buildQuery ( string $query, array $records ) : string
$query string SQL query
$records array Records of the query
return string
Example #1
0
 /**
  * Method to query records in the database
  * 
  * @access private static
  * @param string $query SQL query
  * @param string $type Return type of the query
  * @param string $use Pseudonym of a connection instance
  * @param boolean $count OPTIONAL Counts the number of rows affected
  * @return mixed
  * @throws \PDOException
  */
 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;
 }