duanlan4801 2017-03-04 03:13
浏览 67

无胖SELECT不返回任何数据

i am using Fat-Free Framework to do rapid prototyping of my application. Now, whenever I try to load some data from database, i can use the load() function within the SQL\Mapper but it returned all of the column.

I found SELECT() function but it does not returning any data.

$this->load(['myId=?',$id]) will return the data along with the other columns

$this->select('name',['myId=?',$id]) should return the data from name column but i got nothing.

$this->db->exec('SELECT name FROM persons WHERE myId=?',$id) will return the the data from name column.

what is the proper way of using SELECT() from Fat-Free framework? my goal is to only retrieve single data from name column only.

  • 写回答

1条回答 默认 最新

  • dongqiaochi2711 2019-01-15 10:12
    关注

    The right way to do it is like this:

    $table = new DB\SQL\Mapper($db, 'persons');
    // assign to $results
    $results = $table->load(array('myId=?', $id));
    
    foreach($results => $row){
      echo $row->name;
    }
    

    As described here: https://fatfreeframework.com/3.6/databases#SeekandYouShallFind

    评论

报告相同问题?