Skip to content

Latest commit

 

History

History
52 lines (38 loc) · 1.44 KB

pdostatement-fetchobject.md

File metadata and controls

52 lines (38 loc) · 1.44 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic
PDOStatement::fetchObject
API reference for the PDOStatement::fetchObject function in the Microsoft PDO_SQLSRV Driver for PHP for SQL Server.
David-Engel
davidengel
08/10/2020
sql
connectivity
reference

PDOStatement::fetchObject

[!INCLUDEDriver_PHP_Download]

Retrieves the next row as an object.

Syntax

  
mixed PDOStatement::fetchObject([ $class_name[,$ctor_args ]] )  

Parameters

$class_name: An optional string specifying the name of the class to create. The default is stdClass.

$ctor_args: An optional array with arguments to a custom class constructor.

Return Value

On success, returns an object with an instance of the class. Properties map to columns. Returns false on failure.

Remarks

Support for PDO was added in version 2.0 of the [!INCLUDEssDriverPHP].

Example

<?php  
   $server = "(local)";  
   $database = "AdventureWorks";  
   $conn = new PDO( "sqlsrv:server=$server ; Database = $database", "", "");  
  
   $stmt = $conn->query( "select * from Person.ContactType where ContactTypeID < 5 " );  
   $result = $stmt->fetchObject();  
   print $result->Name;  
?>  

See Also

PDOStatement Class

PDO