欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php读取mysql入门实例

程序员文章站 2022-06-05 16:20:57
...

例子,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. ?>
复制代码