1 链接mysql 数据简单测试
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
$mysqli = new mysqli();
$mysqli->connect("localhost","root","sulin","test");
if($mysqli->errno == 0)
{
$sql = "SELECT * FROM table_1";
$result = $mysqli->query($sql);
echo "<br/>Result row nums:".$result->num_rows."<br/>";
while(list($id,$name,$birthday,$remark) = $result->fetch_row())
{
echo "$id : $name : $birthday : $remark"."<br/>";
}
}
else
{
echo "The Connection is Error!";
exit();
}
$mysqli->close();
?>
</body>
</html>
mysql 设置:
ALTER DATABASE test DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE table_1 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
SET character_set_client='utf8';
SET character_set_connection='utf8';
SET character_set_results='utf8';
php 和mysql 的字符设置必须一样,否则就是乱码