map¶
Maps the result to an object.
Parameters¶
map($sql, $class_name=null, $params=array())
$sql: | The MySQL query to perfom on the database. |
---|---|
$class_name: | The name of the class to instantiate, set the properties of and return. If not specified, a stdClass object is returned. |
$params: | An optional array of parameters to pass to the constructor for $class_name objects. |
Example¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <?php
require_once 'dalmp.php';
$user = getenv('MYSQL_USER') ?: 'root';
$password = getenv('MYSQL_PASS') ?: '';
$host = getenv('MYSQL_HOST') ?: '127.0.0.1';
$port = getenv('MYSQL_PORT') ?: '3306';
$db = new DALMP\Database("utf8://$user:$password@$host:$port/dalmp");
$db->FetchMode('ASSOC');
$ors = $db->map('SELECT * FROM City WHERE Name="Toluca"');
echo sprintf('ID: %d CountryCode: %s', $ors->ID, $ors->CountryCode);
print_r($ors);
|
Output:
1 2 3 4 5 6 7 8 9 10 | ID: 2534 CountryCode: MEX
stdClass Object
(
[ID] => 2534
[Name] => Toluca
[CountryCode] => MEX
[District] => México
[Population] => 665617
)
|
See also
Thanks Navicat for supporting Open Source projects.
A great amount of time has been spent creating, crafting and maintaining this software, please consider donating.
Donating helps ensure continued support, development and availability.
comments powered by Disqus