php动态数组的用法

// 创建连接
$con = new mysqli($servername, $username, $password, $dbname);
// Check conection
if ($con->connect_error) {
    die("连接失败: " . $con->conect_error);
}

$sql = "SELECT * FROM table limit 0,1000";
$result = $con->query($sql);

if ($result->num_rows > 0) {
    // 输出数据
    $mydata = array();
    while($row = $result->fetch_assoc()) {

        $mydate = '2019/04/29';


        $my_post = array(
            'col1'    => $row["col1"],
            'col2'  => $row["col2"],
            'col3'     => '2019-04-29 10:00:00'
            
        );
        $mydata[] = $my_post;
      

    }
} else {
    echo "0 结果";
}
$con->close();

 

你可能感兴趣的:(php)