简体   繁体   English

将PDO :: FETCH_ASSOC转换为SQLite

[英]Convert PDO::FETCH_ASSOC to SQLite

I am hoping to convert some of my basic settings like my navigation, mysql settings (host, username, password) to SQLite but it seems from something I read this morning there is no equivalent for the command PDO::FETCH_ASSOC . 我希望将一些基本设置(如导航,mysql设置(主机,用户名,密码))转换为SQLite,但从我今天上午阅读的内容来看,似乎没有与PDO::FETCH_ASSOC命令等效的设置。 Is there another way for me to do this query that would be compatible with SQLite? 我还有另一种方法可以执行与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;
}
?>

So your $query is SQLite3Result ?? 因此,您的$query是SQLite3Result? try this way then: 然后尝试这种方式:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM