phpmysqldatabaseframeworkskohana

How to get data from database with kohana?


Hy!

I configured the modules/database/database.php file. In controller/index.php I have:

$query = DB::query(Database::SELECT, 'SELECT * FROM posts ORDER By id DESC');

Using phpmyadmin, I created two blog posts, but the script doesn't seem to get them from the database. I don't see any errors and also the blog posts are not visible.

P.S. Sorry for my bad English, I am a schoolboy from Latvia and I'm learning English. :)


Solution

  • please read documentation: "Once you are done building, you can execute the query using execute() and use the results."

    $query = DB::query(Database::SELECT, 'SELECT * FROM posts ORDER By id DESC')->execute();
    

    Now you can use foreach.

    foreach($query as $item){  ..  }