对于含有中文的数据插入,需要添加
mysqli_query($conn , "set names utf8");
插入数据:
INSERT INTO table_name (field1, field2,...fieldN) VALUES (valueA1,valueA2,...valueAN),(valueB1,valueB2,...valueBN),(valueC1,valueC2,...valueCN)......;
查询数据:
$sql = 'SELECT runoob_id, runoob_title,
runoob_author, submission_date
FROM runoob_tbl';
$retval = mysqli_query( $conn, $sql );//获取数据
if(! $retval )
{
die('无法读取数据: ' . mysqli_error($conn));
}
while($row = mysqli_fetch_array($retval, MYSQLI_ASSOC))//使用或输出所有查询的数据
{
echo "<tr><td> {$row['runoob_id']}</td> ".
"<td>{$row['runoob_title']} </td> ".
"<td>{$row['runoob_author']} </td> ".
"<td>{$row['submission_date']} </td> ".
"</tr>";
}
更新数据:
$sql = 'UPDATE runoob_tbl
SET runoob_title="学习 Python"
WHERE runoob_id=3';
删除数据:
$sql = 'DELETE FROM runoob_tbl
WHERE runoob_id=3';