notorm icon indicating copy to clipboard operation
notorm copied to clipboard

Cannot set fetch mode - always set to PDO::FETCH_ASSOC

Open Mariyo opened this issue 9 years ago • 1 comments

Hi, this is not a bug, but maybe feature request. It would be cool, if I would able to decide, which fetching mode will be used in results. I would like to get result as instances of object:

foreach ($db->application()->fethmode(PDO::FETCH_CLASS, 'MyApplicationClass') as $application) {
    // get all applications as instances of class: "MyApplicationClass"
    echo "$application->title\n"; // print application title
}

Mariyo avatar Nov 14 '16 15:11 Mariyo

Very old issue, but for those still looking for it:

The PDO connection used to instantiate NotORM can be set up to return objects: https://www.php.net/manual/en/pdo.setattribute.php#101800

So based on the setup snippet from notorm.com:

include "NotORM.php";
$pdo = new PDO("mysql:dbname=software");
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
$db = new NotORM($pdo);

fvgoto avatar Sep 28 '23 20:09 fvgoto