function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('msql')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; $user = $dsninfo['username']; $pw = $dsninfo['password']; $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost'; $connect_function = $persistent ? 'msql_pconnect' : 'msql_connect'; if ($dbhost && $user && $pw) { $conn = $connect_function($dbhost, $user, $pw); } elseif ($dbhost && $user) { $conn = $connect_function($dbhost, $user); } else { $conn = $connect_function($dbhost); } if (!$conn) { $this->raiseError(DB_ERROR_CONNECT_FAILED); } if (!@msql_select_db($dsninfo['database'], $conn)) { return $this->raiseError(DB_ERROR_NODBSELECTED); } $this->connection = $conn; return DB_OK; }
function SelectDatabase() { if (!strcmp($this->database_name, "")) { return $this->SetError("Select database", "It was not specified a valid database name to select"); } $last_connection = $this->connection; if (!$this->Connect()) { return 0; } if ($last_connection == $this->connection && strcmp($this->selected_database, "") && !strcmp($this->selected_database, $this->database_name)) { return 1; } if (!msql_select_db($this->database_name, $this->connection)) { return $this->SetError("Select database", msql_error()); } $this->selected_database = $this->database_name; return 1; }
function sql_connect($host, $user, $password, $db) { global $dbtype; switch ($dbtype) { case "MySQL": $dbi = @mysql_connect($host, $user, $password); mysql_select_db($db); return $dbi; break; case "mSQL": $dbi = msql_connect($host); msql_select_db($db); return $dbi; break; case "postgres": $dbi = @pg_connect("host={$host} user={$user} password={$password} port=5432 dbname={$db}"); return $dbi; break; case "postgres_local": $dbi = @pg_connect("user={$user} password={$password} dbname={$db}"); return $dbi; break; case "ODBC": $dbi = @odbc_connect($db, $user, $password); return $dbi; break; case "ODBC_Adabas": $dbi = @odbc_connect($host . ":" . $db, $user, $password); return $dbi; break; case "Interbase": $dbi = @ibase_connect($host . ":" . $db, $user, $password); return $dbi; break; case "Sybase": $dbi = @sybase_connect($host, $user, $password); sybase_select_db($db, $dbi); return $dbi; break; default: break; } }
function OpenDataBase($dbinfo) { global $msql_db; if (!($dbc = msql_connect())) { $msg = gettext("Cannot establish connection to database, giving up."); $msg .= "<BR>"; $msg .= sprintf(gettext("Error message: %s"), msql_error()); ExitWiki($msg); } if (!msql_select_db($msql_db, $dbc)) { $msg = gettext("Cannot open database %s, giving up."); $msg .= "<BR>"; $msg .= sprintf(gettext("Error message: %s"), msql_error()); ExitWiki($msg); } $dbi['dbc'] = $dbc; $dbi['table'] = $dbinfo['table']; // page metadata $dbi['page_table'] = $dbinfo['page_table']; // page content return $dbi; }
/** * Connect to the database server, log in and open the database * * Don't call this method directly. Use DB::connect() instead. * * Example of how to connect: * <code> * require_once 'DB.php'; * * // $dsn = 'msql://hostname/dbname'; // use a TCP connection * $dsn = 'msql:///dbname'; // use a socket * $options = array( * 'portability' => DB_PORTABILITY_ALL, * ); * * $db =& DB::connect($dsn, $options); * if (PEAR::isError($db)) { * die($db->getMessage()); * } * </code> * * @param array $dsn the data source name * @param bool $persistent should the connection be persistent? * * @return int DB_OK on success. A DB_Error object on failure. */ function connect($dsn, $persistent = false) { if (!PEAR::loadExtension('msql')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsn; if ($dsn['dbsyntax']) { $this->dbsyntax = $dsn['dbsyntax']; } $params = array(); if ($dsn['hostspec']) { $params[] = $dsn['port'] ? $dsn['hostspec'] . ',' . $dsn['port'] : $dsn['hostspec']; } $connect_function = $persistent ? 'msql_pconnect' : 'msql_connect'; $ini = ini_get('track_errors'); $php_errormsg = ''; if ($ini) { $this->connection = @call_user_func_array($connect_function, $params); } else { ini_set('track_errors', 1); $this->connection = @call_user_func_array($connect_function, $params); ini_set('track_errors', $ini); } if (!$this->connection) { if (($err = @msql_error()) != '') { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $err); } else { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $php_errormsg); } } if (!@msql_select_db($dsn['database'], $this->connection)) { return $this->msqlRaiseError(); } return DB_OK; }
function sql_connect($host, $user, $password, $db) { global $dbtype; switch ($dbtype) { case "MySQL": $dbi = @mysql_connect($host, $user, $password); if (!mysql_select_db($db)) { mysql_query("CREATE DATABASE {$db}"); mysql_select_db($db); include 'install.php'; die; } return $dbi; break; case "mSQL": $dbi = msql_connect($host); if (!msql_select_db($db)) { msql_query("CREATE DATABASE {$db}"); msql_select_db($db); include 'install.php'; die; } return $dbi; break; case "PostgreSQL": $dbi = @pg_connect("host={$host} user={$user} password={$password} port=5432 dbname={$db}"); return $dbi; break; case "PostgreSQL_local": $dbi = @pg_connect("user={$user} password={$password} dbname={$db}"); return $dbi; break; case "ODBC": $dbi = @odbc_connect($db, $user, $password); return $dbi; break; case "ODBC_Adabas": $dbi = @odbc_connect($host . ":" . $db, $user, $password); return $dbi; break; case "Interbase": $dbi = @ibase_connect($host . ":" . $db, $user, $password); return $dbi; break; case "Sybase": $dbi = @sybase_connect($host, $user, $password); if (!sybase_select_db($db, $dbi)) { sybase_query("CREATE DATABASE {$db}", $dbi); sybase_select_db($db, $dbi); include 'install.php'; die; } return $dbi; break; default: break; } }
function connect_msql($host, $user, $pass, $db) { $this->msql_link = msql_connect($host, $user, $pass); if ($this->msql_link == 0) { return false; } if (!msql_select_db($db, $this->msql_link)) { print "Database Error " . msql_error(); return false; } return $this->msql_link; }