2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 11/16/2003 *
4 * =================== Last change: 12/13/2004 *
6 * -------------------------------------------------------------------- *
7 * File : mysql-connect.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Connects to your database *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Verbindet zu Ihrer Datenbank *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2009 by Roland Haeder *
21 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
45 // Load more function libraries or includes
46 foreach (array('request-functions', 'session-functions', 'code-functions', 'language-functions', 'sql-functions', 'expression-functions', 'filter-functions','revision-functions', 'filters', 'mysql-manager', 'extensions-functions', 'handler') as $lib) {
47 // Load special functions
48 loadIncludeOnce('inc/' . $lib . '.php');
52 set_error_handler('__errorHandler');
54 // Disable block-mode by default
55 enableBlockMode(false);
66 // Set important header_sent
67 if (!isset($GLOBALS['header_sent'])) $GLOBALS['header_sent'] = '0';
69 // Init fatal messages
72 // Init message system
75 // Are we in installation phase?
76 if ((!isInstalling()) && (!isInstallationPhase())) {
77 // Load configuration file(s) here
78 loadIncludeOnce('inc/load_config.php');
80 // Load database layer here
81 loadIncludeOnce('inc/db/lib.php');
84 initExtensionCssFiles();
86 if ((!empty($GLOBALS['mysql']['host'])) && (!empty($GLOBALS['mysql']['login'])) && (!empty($GLOBALS['mysql']['password'])) && (!empty($GLOBALS['mysql']['dbase']))) {
88 SQL_CONNECT($GLOBALS['mysql']['host'], $GLOBALS['mysql']['login'], $GLOBALS['mysql']['password'], __FILE__, __LINE__);
91 if (SQL_IS_LINK_UP()) {
92 // Enable exit on error
95 // Is it a valid resource?
96 if (SQL_SELECT_DB($GLOBALS['mysql']['dbase'], __FILE__, __LINE__) === true) {
97 // This is required for extension 'optimize' to work
98 setConfigEntry('__DB_NAME', $GLOBALS['mysql']['dbase']);
100 // Remove MySQL array from namespace
101 unset($GLOBALS['mysql']);
104 loadIncludeOnce('inc/load_cache.php');
106 // Check module for permissions
107 $checkModule = checkModulePermissions();
109 // Admin module should be accessable by guests to login
110 if ((getModule() == 'admin') && ($checkModule == 'admin_only')) {
111 // This is fine and can be ignored
112 } elseif ($checkModule != 'done') {
114 logDebugMessage(__FILE__, __LINE__, sprintf("Check of module %s results in unexpected value: %s",
121 addFatalMessage(__FILE__, __LINE__, getMessage('WRONG_DB_SELECTED'));
124 // No link to database!
125 addFatalMessage(__FILE__, __LINE__, getMessage('NO_DB_LINK'));
128 // Maybe you forgot to enter your MySQL data?
129 addFatalMessage(__FILE__, __LINE__, getMessage('MYSQL_DATA_MISSING'));
132 ///////////////////////////////////////////////////
133 // Include neccessary functions for installation //
134 ///////////////////////////////////////////////////
136 // Default output is 'direct' for HTML output
137 setConfigEntry('OUTPUT_MODE', 'direct');
139 // This hack prevents a backtrace in CSS output
140 if (getOutputMode() == 1) {
141 // Problem with config so set output mode
142 setConfigEntry('OUTPUT_MODE', 'render');
145 // CFG: DATABASE-TYPE
146 setConfigEntry('_DB_TYPE', 'mysql3');
149 foreach (array('inc/db/lib.php','inc/databases.php','inc/session.php','inc/versions.php','inc/install-functions.php','inc/load_config.php') as $inc) {
151 loadIncludeOnce($inc);
154 // Init filter system here
157 // Are we installation routine?
158 if ((!isInstalling()) && (getOutputMode() != 1) && (getOutputMode() != -1)) {
159 // You have to install first!
160 redirectToUrl('install.php');
164 loadIncludeOnce('inc/load_cache.php');
166 // Run the init filter chain
167 runFilterChain('init');
170 // Handle fatal errors
171 runFilterChain('handle_fatal_errors');