douzhi6160 2012-12-10 11:25
浏览 30
已采纳

如何从sqlite db获取行? [关闭]

i am using this PHP code for getting rows but it's getting error

$db = new PDO('sqlite:db/logs');

$result = $db->exec("SELECT * FROM users");

while($row = $result->fetch(SQLITE_ASSOC))
{

}

I am using sqlite3 and php5 and i want to know that

  1. am i connecting with right code to the database i've also used sqlite.open() but it's also getting error?

  2. This new PDO('sqlite:db/logs') connect with database but why new is it create new db everytime

  3. my main problem is i am getting error where while loop is that

Call to a member function fetch() on a non-object

please help me out this i am newbie in php and sqlite

  • 写回答

2条回答 默认 最新

  • dongtangu6889 2012-12-10 11:30
    关注

    You can not use while using PDO, you can use it using procedural approach.

    Some reference: REFERENCE LINK

    You can use $db->exec for insert & update query. Not when you want to fetch the records.

    Try the following changes.

    $db = new PDO('sqlite:db/logs');
    //connection code here
    $result = $db->query("SELECT * FROM users"); //replace exec with query
    
    foreach($result as $row){
        $row['field1'];
        $row['field2'];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?