public function fetchObject(string $sql, array $params = [], $object = 'stdClass')
    {
        $stmt = $this->prepare($sql, $params);

        if (is_string($object)) {
            // some class name
            $result = $stmt->fetchObject($object);
        } else {
            // some instance
            $stmt->setFetchMode(\PDO::FETCH_INTO, $object);
            $result = $stmt->fetch(\PDO::FETCH_INTO);
        }

        $stmt->closeCursor();
        $this->ok();
        return $result;
    }
public function fetchObject(string $sql, array $params = [], $object = 'stdClass')
    {
        $stmt = $this->prepare($sql, $params);

        if (is_string($object)) {
            // some class name
            $result = $stmt->fetchObject($object);
        } else {
            // some instance
            $stmt->setFetchMode(\PDO::FETCH_INTO, $object);
            $result = $stmt->fetch(\PDO::FETCH_INTO);
        }

        $stmt->closeCursor();
        $this->ok();
        return $result;
    }
public function fetchObject ( string $ sql , array $ params = [ ] , $ object = 'stdClass' ) { $ stmt = $ this -> prepare ( $ sql , $ params ) ; if ( is_string ( $ object ) ) { // some class name $ result = $ stmt -> fetchObject ( $ object ) ; } else { // some instance $ stmt -> setFetchMode ( \ PDO :: FETCH_INTO , $ object ) ; $ result = $ stmt -> fetch ( \ PDO :: FETCH_INTO ) ; } $ stmt -> closeCursor ( ) ; $ this -> ok ( ) ; return $ result ; }
Returns an object containing first row from the result set

Example of usage
<code>
// Fetch object to stdClass
$stdClass = $db->fetchObject('SELECT * FROM some_table WHERE id = ?', [$id]);
// Fetch object to new Some object
$someClass = $db->fetchObject('SELECT * FROM some_table WHERE id = ?', [$id], 'Some');
// Fetch object to exists instance of Some object
$someClass = $db->fetchObject('SELECT * FROM some_table WHERE id = ?', [$id], $someClass);
</code>

@param  string $sql    SQL query with placeholders
"SELECT * FROM users WHERE name = :name AND pass = :pass"
@param  array  $params params for query placeholders (optional)
array (':name' => 'John', ':pass' => '123456')
@param  mixed  $object

@return mixed
@throws DbException
Returns an object containing first row from the result set