2011-08-29 20:46 阅读 37



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. :)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    doulao5916 doulao5916 2011-08-30 07:30

    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){  ..  }
    点赞 评论 复制链接分享
  • dongyi9330 dongyi9330 2011-08-30 14:00

    I suggest to use Query Builder where it's possible to accidently avoid SQL injection in the future:

    $query = DB::select()
                ->order_by('id', 'DESC')
    点赞 评论 复制链接分享