PHP connects to mysql, mssql, oracle
- dbtypedef.php
- // Database partial parameter settings
- @define("DATABASE_ACCESS", 0);
- @define("DATABASE_MSSQL", 1);
- @define("DATABASE_ORACLE", 2 );
- @define("DATABASE_MYSQL", 3);
- @define("DATABASE_POSTGRESQL",4);
- @define("DATABASE_SQLITE", 5);
- ?>
-
- /*======= ================================================== =====*/
- /* File name: Model.class.php
- /* Summary: Common parent class model for data access layer database processing). */
- /* Author:
- /* Creation time: 2010- 10-20
- /*============================================== ==================*/
- class Model {
- protected $mysqli; //
- protected $messList; //Prompt message list
- protected $tabName; //Data table
- protected $fieldList; //Data list
- protected $oracle; //Data list
-
- 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 connection failed";
- $e = oci_error();
- trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
- }
- }
- }
- }
Copy code
|