Php 将PDO::FETCH_ASSOC转换为SQLite

Php 将PDO::FETCH_ASSOC转换为SQLite,php,mysql,sqlite,pdo,Php,Mysql,Sqlite,Pdo,我希望将我的一些基本设置(如导航、mysql设置(主机、用户名、密码)转换为SQLite,但从我今天早上读到的内容来看,似乎没有与命令PDO::FETCH_ASSOC等效的设置。对于我来说,是否有其他方法可以执行与SQLite兼容的查询 <? $sql = "SELECT * FROM menu_items WHERE status = 'ACTIVE' ORDER BY menu_parent_id ASC, sortorder ASC, menu_item_name ASC"; $qu

我希望将我的一些基本设置(如导航、mysql设置(主机、用户名、密码)转换为SQLite,但从我今天早上读到的内容来看,似乎没有与命令
PDO::FETCH_ASSOC
等效的设置。对于我来说,是否有其他方法可以执行与SQLite兼容的查询

<?
$sql = "SELECT * FROM menu_items WHERE status = 'ACTIVE' ORDER BY menu_parent_id ASC, sortorder ASC, menu_item_name ASC";
$query = $db->query($sql);

$menu_items = array();

while($data = $query->fetch(PDO::FETCH_ASSOC)) {
    if($data['menu_parent_id'] == 0) {
        $menu_items[$data['menu_item_id']] = array();
        $menu_items[$data['menu_item_id']]['menu_item_id'] = $data['menu_item_id'];
        $menu_items[$data['menu_item_id']]['name'] = $data['menu_item_name'];
        $menu_items[$data['menu_item_id']]['url'] = $data['menu_url'];
        $menu_items[$data['menu_item_id']]['fontawesome'] = $data['fontawesome'];
        $menu_items[$data['menu_item_id']]['children'] = array();
    } else if($data['menu_parent_id'] != 0) {
        $tmp = array();
        $tmp['menu_item_id'] = $data['menu_item_id'];
        $tmp['name'] = $data['menu_item_name'];
        $tmp['url'] = $data['menu_url'];
        $tmp['fontawesome'] = $data['fontawesome'];
        array_push($menu_items[$data['menu_parent_id']]['children'],$tmp);
        unset($tmp);
    }
}

function create_list($arr)
{
    $html = "";
    foreach($arr as $key => $value) {
        //Here the menu item has children
        if(count($value['children']) > 0) {
            $html .= '<!-- PARENT --> <li class="mm-dropdown"> <a href="'. $value['url'] .'"><i class="menu-icon fa '. $value['fontawesome']. '"></i><span class="mm-text">'.$value['name'].'</span></a>

                        <ul>';

            // Here it is the child
            foreach($value['children'] AS $child) {
                $html .= '  
                        <!-- child --><li><a href="'. $child['url'] .'" tabindex="-1" id="'.$child['menu_item_id'].'"><i class="menu-icon fa '. $child['fontawesome']. '"></i>'.$child['name'].'</a></li>';
            }

            $html .= '  </ul>
                        ';
        } else{
            $html .= '  <a class="menu-icon fa '.$value['fontawesome'].'" id="'.$value['menu_item_id'].'" >'.$value['name'].'</a>';
        }
    }

    return $html;
}
?>

那么您的
$query
就是SQLite3Result?? 那就这样试试吧:


while($data=$query->fetchArray(SQLITE3_ASSOC)){

只要省略
PDO::FETCH_ASSOC
就可以了!那你有什么问题吗?你有什么错误吗?非常感谢你,我在查看时没有找到SQLITE3_ASSOC命令,现在它工作得很好。