php鏈接數據庫簡單基礎流程
阿新 • • 發佈:2018-05-31
lose local OS arr con fetch 數據 close HP
<?php
// 假定數據庫用戶名:root,密碼:root,數據庫:test
$con=mysqli_connect("localhost","root","root","test");
if (mysqli_connect_errno($con))
{
echo "連接 MySQL 失敗: " . mysqli_connect_error();
}
// 執行查詢
$aa=mysqli_query($con,"SELECT a.title,a.content,b.name FROM la_blog AS a LEFT JOIN la_cate b ON a.id=b.id");//通過左鏈接關聯查詢表
$arr=[];
while ($row=mysqli_fetch_array($aa)) {
$arr[]=$row;
}
// var_dump($arr);
$bb=mysqli_query($con,"SELECT SUM(title) AS num FROM la_blog");//查看la_blog表的數據條數
$row=mysqli_fetch_array($bb);
var_dump($row[‘num‘]);
mysqli_close($con);
?>
php鏈接數據庫簡單基礎流程