将PDO :: FETCH_ASSOC转换为SQLite

时间:2015-02-19 02:15:17

标签: 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";
$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;
}
?>

1 个答案:

答案 0 :(得分:1)

所以你的$query是SQLite3Result? 然后尝试这样:

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