Home  >  Article  >  Backend Development  >  Simple example of php operating database

Simple example of php operating database

WBOY
WBOYOriginal
2016-07-25 08:57:48837browse
  1. //1, connect to the database

  2. $conn = mysql_connect('127.0.0.1','root','root');
  3. if(!$conn){
  4. die("Connection failed".mysql_error);
  5. }

  6. //2, select database

  7. mysql_select_db("test");

  8. //3 , send the operation statement

  9. $sql="select * from user";

  10. //4, receive the result

  11. $res=mysql_query($sql,$conn);

  12. //5, traversal results

  13. while($row=mysql_fetch_row($res)){
  14. echo "
    $row[0]--$row[1]--$row[2 ]";
  15. } // bbs.it-home.org

  16. //6, close

  17. mysql_free_result($res);
  18. mysql_close($conn);
  19. ?>
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