Db::getObject

Usage

?object Db::getObject(string $class_name, string $sql, [ ... $args ])

Description

Get the first row retrived mapped to an object.

Parameters

Parameter Required Type Description
$class_name Yes string The fully qualified class name to map the record to.
$sql Yes string The SQL statement to execute, which can contain placeholders (ie. %s, %i, %b, et al). For full details, please see the Database Placeholders page of the documentation.
$args No desc=

Return Value

Returns an object with its properties mapped to the record, or null if no record exists.

Examples

Get Object


use App\Demo\Models\Product; $id = 61; if (!$product = $this->getObject(Product::class, "SELECT * FROM prodcuts WHERE id = %i", $id)) { die("No product found with id# $id"); } echo "Got product: " . $product::class . "\n";

See Also