/ LJCPHPCodeDoc / LJCDataManagerLib / LJCDataManager / CreateDataObject


Parameters
$dataObject - A Data Object to use as a template.
$row - An array of data columns.

Returns

A data object record.

Syntax

PHP
public function CreateDataObject($dataObject, array $row)

Populates a typed Data Object with values from a DB row.

Remarks

This method provides Object to Relational Mapping (ORM) as it maps the data columns to properties in the DataObject and copies the matching values.

The data column keys which are the result set column names must match property names in the DataObject.

Example

PHP
 $webCommonPath = "c:/inetpub/wwwroot/LJCPHPCommon";
 require_once "$webCommonPath/LJCDBAccessLib.php";
 
 // See constructor for how to create $connectionValues.
 $manager = new LJCDataManager($connectionValues, "TableName");
 
 class Person
 {
   public int $ID;
   public ?string $Name;
 }
 
 $keyColumns = new LJCDbColumns();
 $keyColumns->Add("ID", value: 1);
 $row = $manager->Retrieve($keyColumns);
 
 $dataObject = new Person();
 $person = $manager->CreateDataObject($dataObject, $row);
 echo $person->ID;
 echo $person->Name;

Copyright © Lester J. Clark and Contributors.
Licensed under the MIT License.