将SQL结果转换为PHP数组
发布时间:2021-03-17 15:24:48 所属栏目:MsSql教程 来源:网络整理
导读:我对PHP很新,我一直在环顾四周,似乎无法找到我正在寻找的具体答案. 我想创建一个SQL查询,例如: $result = mysqli_query($connection,$command)if (!$result) { die("Query Failed."); }// Create my array here ... I'm thinking of maybe having to// make
我对PHP很新,我一直在环顾四周,似乎无法找到我正在寻找的具体答案. 我想创建一个SQL查询,例如: $result = mysqli_query($connection,$command) if (!$result) { die("Query Failed."); } // Create my array here ... I'm thinking of maybe having to // make a class that can hold everything I need,but I dunno while($row = mysqli_fetch_array($result)) { // Put the row into an array or class here... } mysqli_close($connection); // return my array or class 基本上我想获取结果的全部内容并创建一个我可以以与行类似的方式访问的数组.例如,如果我有一个名为’uid’的字段,我希望能够通过myData [‘uid’]获得该字段.我想因为可能有几行,可能更像myData [0] [‘uid’],myData [1] [‘uid’]等. 任何帮助,将不胜感激. 解决方法你可以做:$rows = []; while($row = mysqli_fetch_array($result)) { $rows[] = $row; } (编辑:威海站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |