src/FreeFW/Storage/PDOStorage.php
public function select(\FreeFW\Core\StorageModel &$p_model, array $p_conditions = [])
    {
        $source     = $p_model::getSource();
        $properties = $p_model::getProperties();
        $values     = [];
        $result     = \FreeFW\DI\DI::get('FreeFW::Model::ResultSet');
        /**
         * @var \FreeFW\Model\Condition $oneCondition
         */
        $where = '';
        foreach ($p_conditions as $idx => $oneCondition) {
            $part = $this->renderCondition($oneCondition);
            if ($where != '') {
                $where = $where . ' AND ';
            }
            $where  = $where . $part['sql'];
            $values = array_merge($values, $part['values']);
        }
        // Build query
        $sql = 'SELECT * FROM ' . $source . ' WHERE ' . $where;
        $this->logger->debug('PDOStorage.select : ' . $sql);
        // I got all, run query...
        try {
            // Get PDO and execute
            $query = $this->provider->prepare($sql, array(\PDO::ATTR_CURSOR => \PDO::CURSOR_FWDONLY));
            if ($query->execute($values)) {
                while ($row = $query->fetch(\PDO::FETCH_OBJ)) {
                    $model = clone($p_model);
                    $model
                        ->init()
                        ->setFromArray($row)
                    ;
                    $result[] = $model;
                }
            } else {
                $this->logger->debug('PDOStorage.select.error : ' . print_r($query->errorInfo(), true));
                $localErr = $query->errorInfo();
                $code     = 0;
                $message  = 'PDOStorage.select.error : ' . print_r($query->errorInfo(), true);
                die($message);
                if (is_array($localErr) && count($localErr) > 1) {
                    $code    = intval($localErr[0]);
                    $message = $localErr[2];
                }
                $p_model->addError($code, $message);
            }
        } catch (\Exception $ex) {
            var_dump($ex);
        }
        return $result;
    }
public function select(\FreeFW\Core\StorageModel &$p_model, array $p_conditions = [])
    {
        $source     = $p_model::getSource();
        $properties = $p_model::getProperties();
        $values     = [];
        $result     = \FreeFW\DI\DI::get('FreeFW::Model::ResultSet');
        /**
         * @var \FreeFW\Model\Condition $oneCondition
         */
        $where = '';
        foreach ($p_conditions as $idx => $oneCondition) {
            $part = $this->renderCondition($oneCondition);
            if ($where != '') {
                $where = $where . ' AND ';
            }
            $where  = $where . $part['sql'];
            $values = array_merge($values, $part['values']);
        }
        // Build query
        $sql = 'SELECT * FROM ' . $source . ' WHERE ' . $where;
        $this->logger->debug('PDOStorage.select : ' . $sql);
        // I got all, run query...
        try {
            // Get PDO and execute
            $query = $this->provider->prepare($sql, array(\PDO::ATTR_CURSOR => \PDO::CURSOR_FWDONLY));
            if ($query->execute($values)) {
                while ($row = $query->fetch(\PDO::FETCH_OBJ)) {
                    $model = clone($p_model);
                    $model
                        ->init()
                        ->setFromArray($row)
                    ;
                    $result[] = $model;
                }
            } else {
                $this->logger->debug('PDOStorage.select.error : ' . print_r($query->errorInfo(), true));
                $localErr = $query->errorInfo();
                $code     = 0;
                $message  = 'PDOStorage.select.error : ' . print_r($query->errorInfo(), true);
                die($message);
                if (is_array($localErr) && count($localErr) > 1) {
                    $code    = intval($localErr[0]);
                    $message = $localErr[2];
                }
                $p_model->addError($code, $message);
            }
        } catch (\Exception $ex) {
            var_dump($ex);
        }
        return $result;
    }
public function select ( \ FreeFW \ Core \ StorageModel & $ p_model , array $ p_conditions = [ ] ) { $ source = $ p_model :: getSource ( ) ; $ properties = $ p_model :: getProperties ( ) ; $ values = [ ] ; $ result = \ FreeFW \ DI \ DI :: get ( 'FreeFW::Model::ResultSet' ) ; /**
         * @var \FreeFW\Model\Condition $oneCondition
         */ $ where = '' ; foreach ( $ p_conditions as $ idx => $ oneCondition ) { $ part = $ this -> renderCondition ( $ oneCondition ) ; if ( $ where != '' ) { $ where = $ where . ' AND ' ; } $ where = $ where . $ part [ 'sql' ] ; $ values = array_merge ( $ values , $ part [ 'values' ] ) ; } // Build query $ sql = 'SELECT * FROM ' . $ source . ' WHERE ' . $ where ; $ this -> logger -> debug ( 'PDOStorage.select : ' . $ sql ) ; // I got all, run query... try { // Get PDO and execute $ query = $ this -> provider -> prepare ( $ sql , array ( \ PDO :: ATTR_CURSOR => \ PDO :: CURSOR_FWDONLY ) ) ; if ( $ query -> execute ( $ values ) ) { while ( $ row = $ query -> fetch ( \ PDO :: FETCH_OBJ ) ) { $ model = clone ( $ p_model ) ; $ model -> init ( ) -> setFromArray ( $ row ) ; $ result [ ] = $ model ; } } else { $ this -> logger -> debug ( 'PDOStorage.select.error : ' . print_r ( $ query -> errorInfo ( ) , true ) ) ; $ localErr = $ query -> errorInfo ( ) ; $ code = 0 ; $ message = 'PDOStorage.select.error : ' . print_r ( $ query -> errorInfo ( ) , true ) ; die ( $ message ) ; if ( is_array ( $ localErr ) && count ( $ localErr ) > 1 ) { $ code = intval ( $ localErr [ 0 ] ) ; $ message = $ localErr [ 2 ] ; } $ p_model -> addError ( $ code , $ message ) ; } } catch ( \ Exception $ ex ) { var_dump ( $ ex ) ; } return $ result ; }
Select the model

@param \FreeFW\Core\StorageModel $p_model
@param array                     $p_conditions

@return \FreeFW\Model\ResultSet
Select the model