dscpg80066 2017-07-26 12:51
浏览 46
已采纳

SQLite3 Prepared Statements选择重复的结果[重复]

This question already has an answer here:

I'm attempting to convert some old sqlite3 database code into sqlite3 prepared statements to improve security on my site. I was considering switching to mysql but as of right now I'd like to get this working first.

I can't see what I've done wrong here, but all of my results are doubled.

Here is my code:

$sql = $upc->prepare("SELECT `uid`, `model`, `biosmodel`, `upc`, `systemsku`, `brand`, `hardwareids`, `status`, `pendingHardware` FROM `builds` WHERE `uid`=:id");
$sql->bindValue(':id', $uid, SQLITE3_INTEGER);
$result = $sql->execute();
echo "<pre>".print_r($result->fetchArray(),true)."</pre>";

My result is an array that has all of my keys, but also duplicated entries that seem to just be regular array keys 0-8 with duplicated information, like so:

Array
(
    [0] => 7
    [uid] => 7
    [1] => HP 15-AY041WM
    [model] => HP 15-AY041WM
    [2] => HP Notebook
    [biosmodel] => HP Notebook
    [3] => 889899757697
    [upc] => 889899757697
    [4] => X0H86UA#ABA
    [systemsku] => X0H86UA#ABA
    [5] => HP
    [brand] => HP
    [6] => [42,43,36,44,5,6,45,38,46,41,41,33]
    [hardwareids] => [42,43,36,44,5,6,45,38,46,41,41,33]
    [7] => 0
    [status] => 0
    [8] => 
    [pendingHardware] => 
)

I'm not really sure why this is happening, and obviously I don't want all this duplicated information as it is needless. How can I resolve this issue?

</div>
  • 写回答

1条回答 默认 最新

  • doutusheng5879 2017-07-26 12:57
    关注

    If you just use fetchArray() default it fetches a result row as an associative and numerically indexed array .

    In order to fetch only associative array then pass SQLITE3_ASSOC

    It would be

    $result->fetchArray(SQLITE3_ASSOC);
    

    Read http://php.net/manual/en/sqlite3result.fetcharray.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么