On 03/24/2010 11:16 AM, Arunoda Susiripala wrote:
I'm new to statusnet development.
I was digging the api to find a way to execute a simple sql query and get the result as an array or mixed!

I need something like this.

global $DB;
$res=$DB->query("SELECT * FROM profile");

Using the database object wrappers, you would usually do this something like:

$profile = new Profile();
// set some constraints on the query by putting values into the fields etc...
$profile->find();
while ($profile->fetch()) {
   // do something with $profile->id, $profile->nickname, etc
}


If you need to control the exact query but can still use the wrappers to read the results conveniently, you can use the query() method instead of find():

$profile->query('select * from bla bla concat(fklsdjlksfdjre)');

There's also all kinds of other fancy stuff; google around for docs on DB_DataObject for various examples.


If you really need the lower-level database interfaces that'll return rows as arrays etc, you can dig in and grab the PEAR::DB database connection objects out of the data objects.

-- brion
_______________________________________________
StatusNet-dev mailing list
[email protected]
http://lists.status.net/mailman/listinfo/statusnet-dev

Reply via email to