src/SweetORM/Database/Query.php
public function custom($sql, $bind = array())
    {
        // Prepare query
        $query = ConnectionManager::getConnection()->prepare($sql);

        // Bind when needed
        if (count($bind) > 0) {
            $numericBinding = true;

            // Check if we are going to use the numeric binding
            foreach($bind as $key => $value) {
                if (is_int($key)) {
                    continue;
                }else{
                    $numericBinding = false; // @codeCoverageIgnore
                    if (substr($key, 0, 1) !== ':') { // @codeCoverageIgnore
                        throw new QueryException("When binding, you should use numeric keys or keys with : before each key to identify the binding place in the query!"); // @codeCoverageIgnore
                    } // @codeCoverageIgnore
                }
            }

            // Bind it!
            $idx = 1;
            foreach($bind as $key => $value) {
                if ($numericBinding) {
                    if (is_int($value)) {
                        $type = \PDO::PARAM_INT; // @codeCoverageIgnore
                    } elseif(is_bool($value)) {
                        $type = \PDO::PARAM_BOOL; // @codeCoverageIgnore
                    } else {
                        $type = \PDO::PARAM_STR;
                    }
                    $query->bindValue($idx, $value, $type);
                } else {
                    $query->bindValue($key, $value);
                }
            }
        }

        // Set fetch mode
        $query->setFetchMode(\PDO::FETCH_CLASS, $this->class);

        // Execute
        $query->execute();

        // Fetch and return
        return $this->injectState($query->fetchAll());
    }
public function custom($sql, $bind = array())
    {
        // Prepare query
        $query = ConnectionManager::getConnection()->prepare($sql);

        // Bind when needed
        if (count($bind) > 0) {
            $numericBinding = true;

            // Check if we are going to use the numeric binding
            foreach($bind as $key => $value) {
                if (is_int($key)) {
                    continue;
                }else{
                    $numericBinding = false; // @codeCoverageIgnore
                    if (substr($key, 0, 1) !== ':') { // @codeCoverageIgnore
                        throw new QueryException("When binding, you should use numeric keys or keys with : before each key to identify the binding place in the query!"); // @codeCoverageIgnore
                    } // @codeCoverageIgnore
                }
            }

            // Bind it!
            $idx = 1;
            foreach($bind as $key => $value) {
                if ($numericBinding) {
                    if (is_int($value)) {
                        $type = \PDO::PARAM_INT; // @codeCoverageIgnore
                    } elseif(is_bool($value)) {
                        $type = \PDO::PARAM_BOOL; // @codeCoverageIgnore
                    } else {
                        $type = \PDO::PARAM_STR;
                    }
                    $query->bindValue($idx, $value, $type);
                } else {
                    $query->bindValue($key, $value);
                }
            }
        }

        // Set fetch mode
        $query->setFetchMode(\PDO::FETCH_CLASS, $this->class);

        // Execute
        $query->execute();

        // Fetch and return
        return $this->injectState($query->fetchAll());
    }
public function custom ( $ sql , $ bind = array ( ) ) { // Prepare query $ query = ConnectionManager :: getConnection ( ) -> prepare ( $ sql ) ; // Bind when needed if ( count ( $ bind ) > 0 ) { $ numericBinding = true ; // Check if we are going to use the numeric binding foreach ( $ bind as $ key => $ value ) { if ( is_int ( $ key ) ) { continue ; } else { $ numericBinding = false ; // @codeCoverageIgnore if ( substr ( $ key , 0 , 1 ) !== ':' ) { // @codeCoverageIgnore throw new QueryException ( "When binding, you should use numeric keys or keys with : before each key to identify the binding place in the query!" ) ; // @codeCoverageIgnore } // @codeCoverageIgnore } } // Bind it! $ idx = 1 ; foreach ( $ bind as $ key => $ value ) { if ( $ numericBinding ) { if ( is_int ( $ value ) ) { $ type = \ PDO :: PARAM_INT ; // @codeCoverageIgnore } elseif ( is_bool ( $ value ) ) { $ type = \ PDO :: PARAM_BOOL ; // @codeCoverageIgnore } else { $ type = \ PDO :: PARAM_STR ; } $ query -> bindValue ( $ idx , $ value , $ type ) ; } else { $ query -> bindValue ( $ key , $ value ) ; } } } // Set fetch mode $ query -> setFetchMode ( \ PDO :: FETCH_CLASS , $ this -> class ) ; // Execute $ query -> execute ( ) ; // Fetch and return return $ this -> injectState ( $ query -> fetchAll ( ) ) ; }
Execute custom query.

@param string $sql
@param array $bind

@throws QueryException
@throws \PDOException

@return Entity[]
Execute custom query .