有没有办法将sqlite表输出到php数组?
我目前正在尝试使用while循环,但它无法正确显示。
$db = sqlite_open ("products.db", 0666, $error);
$result=sqlite_query($db,"SELECT * from Books");
$products = array();
while($row=sqlite_fetch_array($result,SQLITE_ASSOC))
{
$products = $row;
}
我想将它存储到2D php数组中,就像它一样:
$products = array(
1 => array(
'name' => '',
'price' => ,
'category' => '',
'description' => ''
),
2 => array(
'name' => '',
'price' => ,
'category' => '',
'description' => ''
),
3 => array(
'name' => '',
'price' => ,
'category' => '',
'description' => ''
)
);
答案 0 :(得分:4)
你很亲密。您只需要将每行添加到数组中,而不是覆盖当前正在执行的数组变量。
while($row=sqlite_fetch_array($result,SQLITE_ASSOC))
{
$products[] = $row;
}