Php connection to mysql, mssql, and oracle
Php connection to mysql, mssql, and oracle
- Dbtypedef. php
- // Some database 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 database processing at the data access layer ).*/
- /* Author:
- /* Creation Time: 2010-10-20
- /* ===================================================== ======================================= */
- Class Model {
- Protected $ mysqli ;//
- Protected $ messList; // list of prompt messages
- 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 );
- }
- }
- }
- }
|