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

如何从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条)

报告相同问题?

悬赏问题

  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行