doutao6653 2013-07-24 13:29
浏览 116
已采纳

SQLite查询中的PHP变量

I'm a beginner with web-related coding and I'm trying to make a web-interface from where I can read and write to the sqlite database. My current problem is implementing a PHP-variable ($inNodeID) to sqlite query:

SELECT * FROM data WHERE NodeID = "$inNodeID"

If I replace the variable in query to the value of the variable ("ID007") everything seems to work. So what is wrong with my syntax in this manner?

    $inNodeID = "ID007";
    echo "Requested node: $inNodeID 
";

    print "<table border=1>";
    print "<tr><td>NodeID</td><td>MemoryIndex</td><td>DataIndex</td><td>TimeStamp</td></tr>";
    $result = $db->query('SELECT * FROM data WHERE NodeID = "$inNodeID"');
    //$result->bindParam(':inNodeID', $inNodeID, PDO::PARAM_STR);

    foreach($result as $row)
    {
    print "<td>".$row['NodeID']."</td>";
    print "<td>".$row['MemoryIndex']."</td>";
    print "<td>".$row['DataIndex']."</td>";
    print "<td>".$row['TimeStamp']."</td></tr>";
    }
    print "</table>";
  • 写回答

5条回答 默认 最新

  • doujingtang6580 2013-07-24 13:33
    关注

    It seems you were about to use the right way but for some reason gave up

    Here you go:

    $result = $db->prepare('SELECT * FROM data WHERE NodeID = ?');
    $result->execute(array($inNodeID));
    $data = $result->fetchAll();
    
    foreach($data as $row)
    ...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器