将 PDO::FETCH_ASSOC 转换为 SQLite

Convert PDO::FETCH_ASSOC to SQLite

我希望将我的一些基本设置(例如我的导航)、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)) {