Home >Backend Development >PHP Tutorial >PHP reading mysql database entry example

PHP reading mysql database entry example

WBOY
WBOYOriginal
2016-07-25 09:11:53976browse

PHP reading mysql database entry example

Full code:

  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. //Detect data connection
  8. if (mysqli_connect_errno()){
  9. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  10. }
  11. $sql = "select * from keyword";
  12. $result = mysqli_query($conn, $sql);

  13. < p>//Output mysql data query results
  14. while($row = mysqli_fetch_array($result)){
  15. echo $row['keycId'] . " : " .$row['keycontent'] . " : " . $row ['keycause'];
  16. echo "
    ";
  17. }
  18. // Close the connection
  19. mysqli_close($conn);
  20. ?>

Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn