Beispiel #1
0
 public function hydrate(Statement $statement)
 {
     $columnIndex = $this->columnIndex;
     if (is_string($columnIndex)) {
         $columnCount = $statement->getColumnCount();
         for ($i = 0; $i < $columnCount; $i++) {
             $meta = $statement->getColumnMeta($i);
             if ($meta['name'] == $columnIndex) {
                 $columnIndex = $i;
                 break;
             }
         }
     }
     $res = $statement->fetchAll(PDO::FETCH_COLUMN, $columnIndex);
     if ($res !== false && $this->normalize) {
         foreach ($res as $key => $value) {
             $value = $statement->normalizeRow(array($columnIndex => $value));
             $res[$key] = $value[$columnIndex];
         }
     }
     return $res;
 }
Beispiel #2
0
 /**
  * Common column type detection.
  * @return array
  */
 public static function detectTypes(Statement $statement)
 {
     $types = array();
     $count = $statement->columnCount();
     // driver must be meta-aware, see PHP bugs #53782, #54695
     for ($col = 0; $col < $count; $col++) {
         $meta = $statement->getColumnMeta($col);
         if (isset($meta['native_type'])) {
             $types[$meta['name']] = self::detectType($meta['native_type']);
         }
     }
     return $types;
 }