Question

It's possible get each row as an object like in ezSQL? For example, ezSQL returns(print_r($sql):

Array (
    [0] => stdClass Object (
        [click_time] => 2011-09-12 17:30:06
        [referrer] => direct
        [user_agent] => Mozilla/5.0
        [country_code] => EN
    )
    [1] => stdClass Object (
        [click_time] => 2011-09-14 23:45:35
        [referrer] => direct
        [user_agent] => Mozilla/5.0
        [country_code] => EN
    )
)

But how to do that in adodb ?

Was it helpful?

Solution

ADODB uses resources rather than objects, so you would have to build the object yourself.

Not knowing what version or functions you are using to interact with ADODB, this is only a basic idea, and you need advance knowledge of the fields (unless you get the field list from the resource itself, which generally is possible):

$_GET['id'] = check_input($_GET['id']);
$query1 = "SELECT * FROM stats WHERE shorturl='{$_GET['id']}'";
$result1 = $myDB->Execute($query1) or die(GetDbError($myDB->ErrorMsg()));

$fields = array('click_time', 'referrer', 'user_agent', 'country_code', ...);
$obj = new stdClass;
foreach($fields as $field) $obj->$field = $result1->Fields($field);

What this does is create an object, create a member variable in that object (named with the field name from the database), and set that member variable to the value returned for that database field.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top