Explanation of PHP odbc tips _ PHP Tutorial

Source: Internet
Author: User
Tags dsn
Correctly interpret PHP odbc skills. When we apply odbc code in PHP: classodbc_db {var $ connull; var $ resourcenull; function _ construct () {} functionconnect ($ dsn, $ user, $ passwd, $ cu when we are applying

PHP odbc application code:

  1. Class odbc_db
  2. {
  3. Var $ con = null;
  4. Var $ resource = null;
  5. Function _ construct ()
  6. {
  7. }
  8. Function connect ($ dsn = ",
    $ User = ", $ passwd = ",
    $ Cursor_type = 0)
  9. {
  10. ! $ Dsn & $ this->Debug ('dsn not provided! ');
  11. $ This->Con = odbc_connect ($ dsn, $ user
    , $ Passwd, $ cursor_type );
  12. ! $ This->Con & $ this->Debug ('conncet failed! ');
  13. Return $ this->Con;
  14. }
  15. Function query ($ SQL = ")
  16. {
  17. $ This->Resource = odbc_exec ($ this->Con, $ SQL );
  18. ! $ This->Resource & $ this->Debug
    ('Query failed! ');
  19. Return $ this->Resource;
  20. }
  21. Function fetch_array ($ resource = ")
  22. {
  23. ! $ Resource & $ resource = $ this->Resource;
  24. Return odbc_fetch_array ($ resource );
  25. }
  26. Function query_first ($ SQL = ")
  27. {
  28. $ Resource = $ this->Query ($ SQL );
  29. Return odbc_fetch_array ($ resource );
  30. }
  31. Function fetch_all ($ resource = ")
  32. {
  33. ! $ Resource & $ resource = $ this->Resource;
  34. $ Results = array ();
  35. While (false! ==( $ Row = @ odbc_fetch _
    Array ($ resource )))
  36. {
  37. $ Results [] = $ row;
  38. }
  39. Return $ results;
  40. }
  41. Function num_rows ()
  42. {
  43. Return odbc_num_rows ($ this->Con );
  44. }
  45. Function affected_rows ()
  46. {
  47. Return odbc_num_rows ($ this->Con );
  48. }
  49. Function debug ($ message = ")
  50. {
  51. $ Message. ='
  52. The following error messages are provided by ODBC: '. odbc_errormsg ();
  53. Exit ($ message );
  54. }
  55. Function _ destruct ()
  56. {
  57. Odbc_close ($ this->Con );
  58. }
  59. }
  60. ?>

The above are all the steps for PHP to apply odbc, and I hope to help you.


Specific odbc application code in PHP: classodbc_db {var $ con = null; var $ resource = null; function _ construct () {} functionconnect ($ dsn =, $ user =, $ passwd =, $ cu...

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.