This is useful when we are only dealing with an individual
record. If the query returns more than one record, the first record in the result set will
be used:
$query = 'SELECT * FROM '#__test'';
$db =& JFactory::getDBO();
$db->setQuery($query);
print_r($db->loadAssoc());
Array
(
[id] => 1
[name] => Foo
)
Chapter 3
[ 49 ]
loadAssocList( key : string='' ) : array
This method loads an array of associative arrays or an associative array of associative
arrays. If we specify the parameter key, the returned array uses the record key as the
array key:
$query = 'SELECT * FROM '#__test'';
$db =& JFactory::getDBO();
$db->setQuery($query);
print_r($db->loadAssocList());
Array
(
[0] => Array
(
[id] => 1
[name] => Foo
)
[1] => Array
(
[id] => 2
[name] => Bar
)
)
loadObject( ) : stdClass
This method loads the first record as an object using the table column names as
property names. This is useful when we are only dealing with an individual record. If
the query returns more than one record, the first record in the result set will be used:
$query = 'SELECT * FROM '#__test'';
$db =& JFactory::getDBO();
$db->setQuery($query);
print_r($db->loadObject());
stdClass Object
(
[id] => 1
[name] => Foo
)
The Database
[ 50 ]
loadObjectList( key : string='' ) : array
This method loads an array of stdClass objects or an associative array of stdClass
objects.
Pages:
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80