首頁 >後端開發 >php教程 >php讀取mysql入門實例

php讀取mysql入門實例

WBOY
WBOY原創
2016-07-25 09:12:17975瀏覽

例子,php读取mysql数据。

  1. $hostname = "localhost:3306";

  2. $username = "root";
  3. $password = "root";
  4. $dbname = "test";
  5. $conn = mysqli_connect($hostname, $username, $password, $dbname);
  6. $conn->query("SET NAMES 'gbk'");
  7. // Check connection
  8. if (mysqli_connect_errno()){
  9. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  10. } bbs.it-home.org
  11. $sql = "select * from keyword";
  12. $result = mysqli_query($conn, $sql);

  13. //循环读取mysql数据

  14. while($row = mysqli_fetch_array($result)){
  15. echo $row['keycId'] . " : " .$row['keycontent'] . " : " . $row['keycause'];
  16. echo "
    ";
  17. }
  18. // 关闭连接
  19. mysqli_close($conn);
  20. ?>

复制代码


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn