function dbi_connect($host, $login, $password, $database)
{
    if (strcmp($GLOBALS["db_type"], "mysql") == 0) {
        $c = mysql_pconnect($host, $login, $password);
        if ($c) {
            if (!mysql_select_db($database)) {
                return false;
            }
            return $c;
        } else {
            return false;
        }
    } else {
        if (strcmp($GLOBALS["db_type"], "oracle") == 0) {
            if (strlen($host) && strcmp($host, "localhost")) {
                $c = OCIPLogon("{$login}@{$host}", $password, $database);
            } else {
                $c = OCIPLogon($login, $password, $database);
            }
            $GLOBALS["oracle_connection"] = $c;
            return $c;
        } else {
            if (strcmp($GLOBALS["db_type"], "postgresql") == 0) {
                if (strlen($password)) {
                    $c = pg_connect("host={$host} dbname={$database} user={$login} password={$password}");
                } else {
                    $c = pg_connect("host={$host} dbname={$database} user={$login}");
                }
                $GLOBALS["postgresql_connection"] = $c;
                if (!$c) {
                    echo "Error connecting to database\n";
                    exit;
                }
                return $c;
            } else {
                if (strcmp($GLOBALS["db_type"], "odbc") == 0) {
                    if (strlen($host)) {
                        $c = odbc_pconnect("{$host}:{$database}", $login, $password);
                    } else {
                        $c = odbc_pconnect($database, $login, $password);
                    }
                    $GLOBALS["odbc_connection"] = $c;
                    return $c;
                } else {
                    if (strcmp($GLOBALS["db_type"], "ibase") == 0) {
                        $c = ibase_connect($host, $login, $password);
                        return $c;
                    } else {
                        dbi_fatal_error("dbi_connect(): db_type not defined.");
                    }
                }
            }
        }
    }
}
Example #2
0
 function sql_db($sqlserver, $sqluser, $sqlpassword, $database = "", $persistency = true)
 {
     $this->persistency = $persistency;
     $this->user = $sqluser;
     $this->password = $sqlpassword;
     $this->server = $sqlserver;
     $this->dbname = $database;
     if ($this->persistency) {
         $this->db_connect_id = @OCIPLogon($this->user, $this->password, $this->server);
     } else {
         $this->db_connect_id = @OCINLogon($this->user, $this->password, $this->server);
     }
     if ($this->db_connect_id) {
         return $this->db_connect_id;
     } else {
         return false;
     }
 }
	function _connect($argHostname, $argUsername, $argPassword, $argDatabasename,$mode=0)
	{
		if (!function_exists('OCIPLogon')) return null;


        $this->_errorMsg = false;
		$this->_errorCode = false;

		if($argHostname) { // added by Jorma Tuomainen <*****@*****.**>
			if (empty($argDatabasename)) $argDatabasename = $argHostname;
			else {
				if(strpos($argHostname,":")) {
					$argHostinfo=explode(":",$argHostname);
				   	$argHostname=$argHostinfo[0];
					$argHostport=$argHostinfo[1];
			 	} else {
					$argHostport = empty($this->port)?  "1521" : $this->port;
	   			}

				if ($this->connectSID) {
					$argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname
					.")(PORT=$argHostport))(CONNECT_DATA=(SID=$argDatabasename)))";
				} else
					$argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname
					.")(PORT=$argHostport))(CONNECT_DATA=(SERVICE_NAME=$argDatabasename)))";
			}
		}

 		//if ($argHostname) print "<p>Connect: 1st argument should be left blank for $this->databaseType</p>";
		if ($mode==1) {
			$this->_connectionID = ($this->charSet) ?
				OCIPLogon($argUsername,$argPassword, $argDatabasename,$this->charSet)
				:
				OCIPLogon($argUsername,$argPassword, $argDatabasename)
				;
			if ($this->_connectionID && $this->autoRollback)  OCIrollback($this->_connectionID);
		} elseif ($mode==2) {
			$this->_connectionID = ($this->charSet) ?
				OCINLogon($argUsername,$argPassword, $argDatabasename,$this->charSet)
				:
				OCINLogon($argUsername,$argPassword, $argDatabasename);

		} else {
			$this->_connectionID = ($this->charSet) ?
				OCILogon($argUsername,$argPassword, $argDatabasename,$this->charSet)
				:
				OCILogon($argUsername,$argPassword, $argDatabasename);
		}
		if (!$this->_connectionID) return false;
		if ($this->_initdate) {
			$this->Execute("ALTER SESSION SET NLS_DATE_FORMAT='".$this->NLS_DATE_FORMAT."'");
		}

		// looks like:
		// Oracle8i Enterprise Edition Release 8.1.7.0.0 - Production With the Partitioning option JServer Release 8.1.7.0.0 - Production
		// $vers = OCIServerVersion($this->_connectionID);
		// if (strpos($vers,'8i') !== false) $this->ansiOuter = true;
		return true;
   	}
Example #4
0
/**
 * Opens up a database connection.
 *
 * Use a pooled connection if the db supports it and
 * the <var>db_persistent</var> setting is enabled.
 *
 * <b>Notes:</b>
 * - The database type is determined by the global variable
 *   <var>db_type</var>
 * - For ODBC, <var>$host</var> is ignored, <var>$database</var> = DSN
 * - For Oracle, <var>$database</var> = tnsnames name
 * - Use the {@link dbi_error()} function to get error information if the connection
 *   fails
 *
 * @param string $host     Hostname of database server
 * @param string $login    Database login
 * @param string $password Database login password
 * @param string $database Name of database
 * 
 * @return resource The connection
 */
function dbi_connect($host, $login, $password, $database)
{
    if (strcmp($GLOBALS["db_type"], "mysql") == 0) {
        if ($GLOBALS["db_persistent"]) {
            $c = mysql_pconnect($host, $login, $password);
        } else {
            $c = mysql_connect($host, $login, $password);
        }
        if ($c) {
            if (!mysql_select_db($database)) {
                return false;
            }
            return $c;
        } else {
            return false;
        }
    } else {
        if (strcmp($GLOBALS["db_type"], "mysqli") == 0) {
            if ($GLOBALS["db_persistent"]) {
                $c = @mysqli_connect($host, $login, $password, $database);
            } else {
                $c = @mysqli_connect($host, $login, $password, $database);
            }
            if ($c) {
                /*
                if ( ! mysqli_select_db ( $c, $database ) )
                  return false;
                */
                $GLOBALS["db_connection"] = $c;
                return $c;
            } else {
                return false;
            }
        } else {
            if (strcmp($GLOBALS["db_type"], "mssql") == 0) {
                if ($GLOBALS["db_persistent"]) {
                    $c = mssql_pconnect($host, $login, $password);
                } else {
                    $c = mssql_connect($host, $login, $password);
                }
                if ($c) {
                    if (!mssql_select_db($database)) {
                        return false;
                    }
                    return $c;
                } else {
                    return false;
                }
            } else {
                if (strcmp($GLOBALS["db_type"], "oracle") == 0) {
                    if (strlen($host) && strcmp($host, "localhost")) {
                        $c = OCIPLogon("{$login}@{$host}", $password, $database);
                    } else {
                        $c = OCIPLogon($login, $password, $database);
                    }
                    $GLOBALS["oracle_connection"] = $c;
                    return $c;
                } else {
                    if (strcmp($GLOBALS["db_type"], "postgresql") == 0) {
                        if (strlen($password)) {
                            if (strlen($host)) {
                                $dbargs = "host={$host} dbname={$database} user={$login} password={$password}";
                            } else {
                                $dbargs = "dbname={$database} user={$login} password={$password}";
                            }
                        } else {
                            if (strlen($host)) {
                                $dbargs = "host={$host} dbname={$database} user={$login}";
                            } else {
                                $dbargs = "dbname={$database} user={$login}";
                            }
                        }
                        if ($GLOBALS["db_persistent"]) {
                            $c = pg_pconnect($dbargs);
                        } else {
                            $c = pg_connect($dbargs);
                        }
                        $GLOBALS["postgresql_connection"] = $c;
                        if (!$c) {
                            echo "Error connecting to database\n";
                            exit;
                        }
                        return $c;
                    } else {
                        if (strcmp($GLOBALS["db_type"], "odbc") == 0) {
                            if ($GLOBALS["db_persistent"]) {
                                $c = odbc_pconnect($database, $login, $password);
                            } else {
                                $c = odbc_connect($database, $login, $password);
                            }
                            $GLOBALS["odbc_connection"] = $c;
                            return $c;
                        } else {
                            if (strcmp($GLOBALS["db_type"], "ibm_db2") == 0) {
                                if ($GLOBALS["db_persistent"]) {
                                    $c = db2_pconnect($database, $login, $password);
                                } else {
                                    $c = db2_connect($database, $login, $password);
                                }
                                $GLOBALS["ibm_db2_connection"] = $c;
                                return $c;
                            } else {
                                if (strcmp($GLOBALS["db_type"], "ibase") == 0) {
                                    $host = $host . ":" . $database;
                                    if ($GLOBALS["db_persistent"]) {
                                        $c = ibase_pconnect($host, $login, $password);
                                    } else {
                                        $c = ibase_connect($host, $login, $password);
                                    }
                                    return $c;
                                } else {
                                    if (empty($GLOBALS["db_type"])) {
                                        dbi_fatal_error("dbi_connect(): db_type not defined.");
                                    } else {
                                        dbi_fatal_error("dbi_connect(): invalid db_type '" . $GLOBALS["db_type"] . "'");
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Example #5
0
 function DoConnect()
 {
     if ($this->bConnected) {
         return true;
     }
     $this->bConnected = true;
     if (!defined(DBPersistent)) {
         define("DBPersistent", false);
     }
     if (DBPersistent) {
         $this->db_Conn = @OCIPLogon($this->DBLogin, $this->DBPassword, $this->DBName);
     } else {
         $this->db_Conn = @OCILogon($this->DBLogin, $this->DBPassword, $this->DBName);
     }
     if (!$this->db_Conn) {
         $arError = OCIError();
         if (DBPersistent) {
             $s = "OCIPLogon";
         } else {
             $s = "OCILogon";
         }
         $s .= " Error:" . $arError["message"];
         if ($this->debug || @session_start() && $_SESSION["SESS_AUTH"]["ADMIN"]) {
             echo "<br><font color=#ff0000>" . $s . "('-', '-', '-')</font><br>";
         } else {
             SendError("Error! " . $s . "('-', '-', '-')\n\n");
         }
         return false;
     }
     $this->cntQuery = 0;
     $this->timeQuery = 0;
     $this->arQueryDebug = array();
     global $DB, $USER, $APPLICATION;
     if (file_exists($_SERVER["DOCUMENT_ROOT"] . "/bitrix/php_interface/after_connect.php")) {
         include $_SERVER["DOCUMENT_ROOT"] . "/bitrix/php_interface/after_connect.php";
     }
     return true;
 }