Php connection to mysql, mssql, and oracle

Source: Internet
Author: User
Php connection to mysql, mssql, and oracle
Php connection to mysql, mssql, and oracle

  1. Dbtypedef. php
  2. // Some database parameter settings
  3. @ Define ("DATABASE_ACCESS", 0 );
  4. @ Define ("DATABASE_MSSQL", 1 );
  5. @ Define ("DATABASE_ORACLE", 2 );
  6. @ Define ("DATABASE_MYSQL", 3 );
  7. @ Define ("DATABASE_POSTGRESQL", 4 );
  8. @ Define ("DATABASE_SQLITE", 5 );
  9. ?>
  10. /* ===================================================== ======================================= */
  11. /* File name: Model. class. php
  12. /* Summary: common parent class model for database processing at the data access layer ).*/
  13. /* Author:
  14. /* Creation Time: 2010-10-20
  15. /* ===================================================== ======================================= */
  16. Class Model {
  17. Protected $ mysqli ;//
  18. Protected $ messList; // list of prompt messages
  19. Protected $ tabName; // data table
  20. Protected $ fieldList; // data list
  21. Protected $ oracle; // data list
  22. Public function _ construct (){
  23. If (DB_TYPE = DATABASE_MYSQL)
  24. {
  25. $ This-> mysqli = new mysqli (DB_HOST, DB_USER, DB_PWD, DB_NAME );
  26. $ This-> mysqli-> query ("set names utf8 ");
  27. If (mysqli_connect_errno ()){
  28. Echo "". mysqli_connect_error ();
  29. $ This-> mysqli = FALSE;
  30. Exit ();
  31. }
  32. }
  33. Else if (DB_TYPE = DATABASE_MSSQL)
  34. {
  35. $ Conn = mssql_connect (DB_HOST, DB_USER, DB_PWD) or die ("Couldn't connect to SQL Server on". DB_HOST ."");
  36. Mssql_select_db (DB_NAME, $ conn );
  37. Mssql_query ("set names utf8 ");
  38. }
  39. Else if (DB_TYPE = DATABASE_ORACLE)
  40. {
  41. $ Ora_connstr = "(description = (address = (protocol = tcp) (host = ". DB_HOST. ") (port = ". DB_PORT. ") (connect_data = (service_name = ". DB_NAME. ")))";
  42. $ This-> oracle = oci_connect (DB_USER, DB_PWD, $ ora_connstr );
  43. If (! $ This-> oracle ){
  44. Echo "oracle connection failed ";
  45. $ E = oci_error ();
  46. Trigger_error (htmlentities ($ e ['message'], ENT_QUOTES), E_USER_ERROR );
  47. }
  48. }
  49. }
  50. }

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.