PHP programming advanced programming-a little progress every day

DAY1 mysqli operating database

 

<?php
/**
 * Created by PhpStorm.
 * User: root
 * Date: 3/21/19
 * Time: 2:39 AM
 */
header("content-type: text/html; charset=utf-8");
$db = new mysqli('localhost','geekcloud','MXx_7788120','itcast','3306');
if($db->connect_error){
    die('failed to connect mysql');
}
#('set names utf8');
$db->query('set names utf8');
$sql = "select * from book_list";
$result = $db->query($sql);
echo "<table border = '1' cellspacing = '1' align='center' width= '720'>";
    echo "<tr height = '50' bgcolor='#ccc'>";
        echo"<td width = 50' align='center'>id </td>";
        echo"<td width = 50' align='center'>name </td>";
        echo"<td width = 50' align='center'>date </td>";
        echo"<td width = 50' align='center'>price </td>";
        echo"<td width = 50' align='center'>author </td>";
    echo "</tr>";
while ($row = $result->fetch_row()){
    echo "<tr height='40'>";
        echo"<td width = 50' align='center'>".$row[0]."</td>";
        echo"<td width = 250' align='center'>".$row[1]."</td>";
        echo"<td width = 150' align='center'>".date('Y-m',strtotime($row[2]))."</td>";
        echo"<td width = 50' align='center'>".$row[3]."</td>";
        echo"<td width = 200' align='center'>".$row[4]."</td>";
    echo "</tr>";
}
echo "</table>";

 

Guess you like

Origin blog.csdn.net/geeksoarsky/article/details/88727322