当前位置:Gxlcms > PHP教程 > php连接mysql,mssql,oracle

php连接mysql,mssql,oracle

时间:2021-07-01 10:21:17 帮助过:9人阅读

php连接mysql,mssql,oracle
  1. dbtypedef.php
  2. // 数据库部分参数设置
  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. /* 文件名称: Model.class.php
  12. /* 概要: 数据访问层数据库处理的公共父类模型). */
  13. /* 作者:
  14. /* 创建时间: 2010-10-20
  15. /*==============================================================*/
  16. class Model {
  17. protected $mysqli; //
  18. protected $messList; //提示信息列表
  19. protected $tabName; //数据表
  20. protected $fieldList; //数据列表
  21. protected $oracle; //数据列表
  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连接失败";
  45. $e = oci_error();
  46. trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
  47. }
  48. }
  49. }
  50. }

人气教程排行