Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

Just a simple Query....

posted by zableingruen 9 years ago

Hi guys,

I'm quite new to flourish and experience a small problem.

Following Code fetches some database entries as an array

$this->set('todo',$this->Item->query("SELECT * FROM items"));

This code fetches exactly one entry as AN OBJECT

$this->set('todo',$this->Item->query("SELECT * FROM items WHERE id = $id"));

The fResult documentation says:

By default when retrieving rows from a result object, they are returned as associative arrays.

Any idea how I can get ONE entry as an array?

I forgot:

Fatal error: Cannot use object of type fResult as array in...

Is the error message I get.

posted by zableingruen 9 years ago

fDatabase::query() returns an fResult object. You should then either iterate over the result object or fetch simple data.

Also, please read up about escaping data in fDatabase. In your example you show embedding the $id variable in your SQL string. This is a huge security vulnerability.

posted by wbond 9 years ago