基本的查询业务逻辑,返回 列表数据:data;操作信息:msg;操作状态:status
$query = "SELECT * from os_system";</span><span style="color: #800080;">$data</span> = <span style="color: #800080;">$mysqli</span>->query(<span style="color: #800080;">$query</span>) or <span style="color: #0000ff;">die</span>(<span style="color: #800080;">$mysqli</span>-><span style="color: #000000;">error); </span><span style="color: #800080;">$total</span> = <span style="color: #800080;">$mysqli</span>->query("SELECT found_rows() as total") or <span style="color: #0000ff;">die</span>(<span style="color: #800080;">$mysqli</span>-><span style="color: #000000;">error); </span><span style="color: #800080;">$result</span> = <span style="color: #0000ff;">array</span>('list' => <span style="color: #0000ff;">array</span>(), 'total' => 0<span style="color: #000000;">); </span><span style="color: #800080;">$result</span>['total'] = <span style="color: #800080;">$total</span>->fetch_assoc()['total'<span style="color: #000000;">]; </span><span style="color: #0000ff;">while</span> (<span style="color: #800080;">$row</span> = <span style="color: #800080;">$data</span>-><span style="color: #000000;">fetch_assoc()) { </span><span style="color: #008080;">array_push</span>(<span style="color: #800080;">$result</span>['list'], <span style="color: #800080;">$row</span><span style="color: #000000;">); } </span><span style="color: #0000ff;">exit</span>(JSON(<span style="color: #0000ff;">array</span>('data' => <span style="color: #800080;">$result</span>, 'msg' => 'success', 'status' => '0')));</pre>
标签:24,gt,2024,CURD,-&,result,query,array,total From: https://www.cnblogs.com/iuniko/p/18155670