php连接mysql,mssql,oracle
- dbtypedef.php
-
// 数据库部分参数设置
- @define("DATABASE_ACCESS", 0);
- @define("DATABASE_MSSQL", 1);
- @define("DATABASE_ORACLE", 2);
- @define("DATABASE_MYSQL", 3);
- @define("DATABASE_POSTGRESQL",4);
- @define("DATABASE_SQLITE", 5);
- ?>
-
- /*==============================================================*/
- /* 文件名称: Model.class.php
- /* 概要: 数据访问层数据库处理的公共父类模型). */
- /* 作者:
- /* 创建时间: 2010-10-20
- /*==============================================================*/
- class Model {
- protected $mysqli; //
- protected $messList; //提示信息列表
- protected $tabName; //数据表
- protected $fieldList; //数据列表
- protected $oracle; //数据列表
-
- public function __construct() {
-
- if(DB_TYPE == DATABASE_MYSQL)
- {
- $this->mysqli = new mysqli ( DB_HOST, DB_USER, DB_PWD, DB_NAME );
- $this->mysqli->query("set names utf8");
- if (mysqli_connect_errno ()) {
- echo "" . mysqli_connect_error ();
- $this->mysqli = FALSE;
- exit();
- }
- }
- else if(DB_TYPE == DATABASE_MSSQL)
- {
- $conn=mssql_connect(DB_HOST, DB_USER, DB_PWD)or die("Couldn't connect to SQL Server on ".DB_HOST."");
- mssql_select_db(DB_NAME,$conn);
- mssql_query("set names utf8");
- }
- else if(DB_TYPE == DATABASE_ORACLE)
- {
- $ora_connstr = "(description=(address=(protocol=tcp) (host=".DB_HOST.")(port=".DB_PORT.")) (connect_data=(service_name=".DB_NAME.")))";
- $this->oracle = oci_connect(DB_USER, DB_PWD,$ora_connstr);
- if (!$this->oracle) {
- echo "oracle连接失败";
- $e = oci_error();
- trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
- }
- }
- }
- }
复制代码
|