PHP 学习1.1
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 的字符設置必須一樣,否則就是亂碼
轉載于:https://www.cnblogs.com/linsu/p/3469553.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
- 上一篇: (转载)9个主流的开源许可协议[整理]
- 下一篇: apache+php windows下配