PDOStatement::fetchObject

Fetches the next row and returns it as an object

Description

public objectfalse PDOStatement::fetchObject(stringnull $class = "stdClass", array $constructorArgs = [])

Fetches the next row and returns it as an object. This function is an alternative to PDOStatement::fetch with PDO::FETCH_CLASS or PDO::FETCH_OBJ style.

When an object is fetched, its properties are assigned from respective column values, and afterwards its constructor is invoked.

Parameters

class

Name of the created class.

constructorArgs

Elements of this array are passed to the constructor.

Return Values

Returns an instance of the required class with property names that correspond to the column names or false on failure.

Errors/Exceptions

Emits an error with level E_WARNING if the attribute PDO::ATTR_ERRMODE is set to PDO::ERRMODE_WARNING.

Throws a PDOException if the attribute PDO::ATTR_ERRMODE is set to PDO::ERRMODE_EXCEPTION.

See Also

  • PDOStatement::fetch