PHP代码
- <?php
- header('Content-Type:application/json;charset=utf-8');
- $servername = "localhost";
- $username = "username";
- $password = "password";
- $dbname = "myDB";
- // 创建连接
- $conn = new mysqli($servername, $username, $password, $dbname);
- // 检查连接
- if ($conn->connect_error) {
- die("连接失败: " . $conn->connect_error);
- }
- // 获取当前日期
- $date = date("Y-m-d");
- // 获取数据
- $sql = "SELECT * FROM MyGuests WHERE reg_date LIKE '$date%'";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- // 输出数据
- while($row = $result->fetch_assoc()) {
- echo json_encode($row);
- }
- } else {
- echo "0 结果";
- }
- $conn->close();
- ?>