public function s2o($sql, $params=null, $class_name='')
    {


        //if it has parameters then prepare the statement and execute with the parameters
        //stmts that have already been prepared will reuse the prepared statement
        if(is_array($params) || is_object($params)){

            //convert object parameters
            $param = is_array($params) ? $params : self::paramify($params);

            $stmt = $this->prepare($sql);
            $result = $stmt->execute($params);

            if(!$result){
                return Array();
            }

        //if there
        } else {

            $result = $this->query($sql);
            if(!is_object($result)){
                return Array();
            } else {
                $stmt = $result;
            }

        }

        //if the class_name is set return instances
        if(!preg_match("~^SELECT|EXEC|CALL~i", trim($sql))){
            return $stmt;
        } elseif(!empty($class_name)){
            if(class_exists($class_name)){
                return $stmt->fetchAll(\PDO::FETCH_CLASS, $class_name);
            }
        } else {
            //otherwise return standard objects
            return $stmt->fetchAll(\PDO::FETCH_OBJ);
        }

    }
public function s2o($sql, $params=null, $class_name='')
    {


        //if it has parameters then prepare the statement and execute with the parameters
        //stmts that have already been prepared will reuse the prepared statement
        if(is_array($params) || is_object($params)){

            //convert object parameters
            $param = is_array($params) ? $params : self::paramify($params);

            $stmt = $this->prepare($sql);
            $result = $stmt->execute($params);

            if(!$result){
                return Array();
            }

        //if there
        } else {

            $result = $this->query($sql);
            if(!is_object($result)){
                return Array();
            } else {
                $stmt = $result;
            }

        }

        //if the class_name is set return instances
        if(!preg_match("~^SELECT|EXEC|CALL~i", trim($sql))){
            return $stmt;
        } elseif(!empty($class_name)){
            if(class_exists($class_name)){
                return $stmt->fetchAll(\PDO::FETCH_CLASS, $class_name);
            }
        } else {
            //otherwise return standard objects
            return $stmt->fetchAll(\PDO::FETCH_OBJ);
        }

    }
public function s2o ( $ sql , $ params = null , $ class_name = '' ) { //if it has parameters then prepare the statement and execute with the parameters //stmts that have already been prepared will reuse the prepared statement if ( is_array ( $ params ) || is_object ( $ params ) ) { //convert object parameters $ param = is_array ( $ params ) ? $ params : self :: paramify ( $ params ) ; $ stmt = $ this -> prepare ( $ sql ) ; $ result = $ stmt -> execute ( $ params ) ; if ( ! $ result ) { return Array ( ) ; } //if there } else { $ result = $ this -> query ( $ sql ) ; if ( ! is_object ( $ result ) ) { return Array ( ) ; } else { $ stmt = $ result ; } } //if the class_name is set return instances if ( ! preg_match ( "~^SELECT|EXEC|CALL~i" , trim ( $ sql ) ) ) { return $ stmt ; } elseif ( ! empty ( $ class_name ) ) { if ( class_exists ( $ class_name ) ) { return $ stmt -> fetchAll ( \ PDO :: FETCH_CLASS , $ class_name ) ; } } else { //otherwise return standard objects return $ stmt -> fetchAll ( \ PDO :: FETCH_OBJ ) ; } }
Turn a sql query into an array of objects representing each row returned

@param string $sql A sql string, can be used with :prop to create a prepared statement
@param Array params An array hash of values to match with properties inside prepared statement
@param Object params An object whose properties match with properties inside prepared statement.
@param Array class_name Here you can specify a class_name, so that rows returned are instances of that class_name instead of standard objects
@return array An array of objects representing rows returned
<code>

//without prepared statements
$results = App::$db->s2o("SELECT * FROM pages WHERE pid =1");

//with prepared statement and params array
$results = App::$db->s2o("SELECT * FROM pages WHERE pid =:pid", Array(":pid"=>1));

//with prepared statement and params object
$params = new stdClass();
$params->pid = 1;
$results = App::$db->s2o("SELECT * FROM pages WHERE pid =:pid", $params);

//with prepared statement and params array plus class_name
$results = App::$db->s2o("SELECT * FROM pages WHERE pid =:pid", Array(":pid" => 1), 'Page');

* //without prepared statement and plus class_name, fetches rows from the pages table into Page instances
$results = App::$db->s2o("SELECT * FROM pages", null, 'Page');

</code>
Turn a sql query into an array of objects representing each row returned