php 连接 mysql
时间:2021-07-01 10:21:17
帮助过:10人阅读
//<meta charset="utf-8">
//header(‘Content-Type: text/html;charset=utf-8‘);
$page = 1
;
$datetime = ‘2019-09-07‘
;
try {
$conn =
new mysqli(‘127.0.0.1‘, ‘root‘, ‘root,.‘,‘test‘
);
}
catch (
Exception $e) {
die("数据库连接失败"
);
}
// mysqli_set_charset($conn,‘utf8‘);
$conn->query("SET NAMES ‘UTF8‘"
);
$num_rec_per_page = 10
;
$start_from = (
$page-1) *
$num_rec_per_page;
// LIMIT $start_from, $num_rec_per_page
$sql="SELECT * FROM test where date_format(`datetime`, ‘%Y-%m-%d‘) = ‘
$datetime‘ "
;
$rs=
$conn->query(
$sql);
$codeArr =
[];
if(
$rs->num_rows > 0
) {
// 输出数据
while(
$row =
$rs->
fetch_assoc()){
$tt =
substr(
$row[‘datetime‘], 0, 13
);
$codeArr[
$tt] =
$codeArr[
$tt] ??
[];
array_push(
$codeArr[
$tt],
$row[‘code‘
]);
}
}else {
echo "暂无数据"
;
}
foreach (
$codeArr as $key => &
$value) {
$value =
array_count_values(
$value);
}
unset(
$value);
print_r(
$codeArr);
php 连接 mysql
标签:ade new 失败 span lse style die mysq pre