Title1

Title2

Title3

6-3-2 mysql 與 mysqli 撈資料的差異

mysql

$sql    = "SELECT * FROM `goods` ORDER BY `goods_date` desc";
#送出查詢,回傳查到的資源
$result = mysql_query($sql) or die(mysql_error());//die($sql);

#將撈到資料整理成陣列
while ($goods = $result->fetch_assoc()) {
$all_goods[] = $goods;
}

mysqli

$sql    = "SELECT * FROM `goods` ORDER BY `goods_date` desc";
$result = $mysqli->query($sql) or die($mysqli->connect_error);

//fetch_all() MYSQLI_ASSOC(陣列), MYSQLI_NUM(序號) , MYSQLI_BOTH(兩者)
$all_goods = $result->fetch_all(MYSQLI_ASSOC);