Example of a php database call class

Source: Internet
Author: User
Tags php database
Example of a php database call class

  1. /**

  2. Desc: Database Class call instance suppose your data Class is db_class.php
  3. Link: bbs.it-home.org
  4. Date:
  5. */
  6. Require_once ("db_class.php ");

  7. // 1. create a class and connect to the database

  8. $ Db = new mssql ("dns = aaa; uid = sa; pwd = sa; dbname = test ");

  9. // 2. connect to the database

  10. $ Conn = $ db-> config ("dns = aaa; uid = sa; pwd = sa; dbname = test ");

  11. // 3. select a database

  12. $ Dbname = $ db-> select_db ("test ");

  13. // 4. allow debugging

  14. $ Db-> debug = true;

  15. // 5. execute an SQL statement that does not return results

  16. $ Db-> execute ("insert into test01 (name) values ('this is a test! ')");
  17. // $ Db-> exec ("");

  18. // 6. execute an SQL statement that returns the result

  19. $ Rs = $ db-> query ("select * from test01 ");

  20. // 7. display results in row mode

  21. Echo"
    Display result sets in row mode
    ";
  22. While ($ r = $ db-> fetch_row ($ rs )){
  23. Echo $ r [0]. ":". $ r [1]."
    ";
  24. }

  25. // 8. display results in array mode

  26. $ Rs2 = $ db-> query ("select * from test01 ");

  27. Echo"
    Display result sets in array mode
    ";

  28. While ($ r = $ db-> fetch_array ($ rs2 )){
  29. Echo $ r ["id"]. ":". $ r ["name"]."
    ";
  30. }

  31. // X. release

  32. $ Db-> db_close ();
  33. ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.