Home  >  Article  >  Backend Development  >  PHP connects to mysql, mssql, oracle

PHP connects to mysql, mssql, oracle

WBOY
WBOYOriginal
2016-07-25 09:06:441165browse
PHP connects to mysql, mssql, oracle
  1. dbtypedef.php
  2. // Database partial 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 data access layer database processing). */
  13. /* Author:
  14. /* Creation time: 2010- 10-20
  15. /*============================================== ==================*/
  16. class Model {
  17. protected $mysqli; //
  18. protected $messList; //Prompt message list
  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. }
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