Rewrote 'we' word a little, rewrote mail order to use SQL_INSERTID() instead of anoth...
[mailer.git] / inc / mysql-connect.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 11/16/2003 *
4  * ===================                          Last change: 12/13/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : mysql-connect.php                                *
8  * -------------------------------------------------------------------- *
9  * Short description : Connects to your database                        *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Verbindet zu Ihrer Datenbank                     *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } // END - if
42
43 // Init include file array as it follows same naming scheme
44 foreach ( array(
45                 'stats',
46                 'xml',
47                 'callback',
48                 'referral',
49                 'email',
50                 'request',
51                 'session',
52                 'code',
53                 'language',
54                 'sql',
55                 'expression',
56                 'filter',
57                 'revision',
58                 'extensions') as $lib) {
59         // Load special functions
60         loadIncludeOnce('inc/' . $lib . '-functions.php');
61 } // END - foreach
62
63 // Load more function libraries or includes
64 foreach (array('filters', 'mysql-manager', 'handler') as $lib) {
65         // Load special functions
66         loadIncludeOnce('inc/' . $lib . '.php');
67 } // END - foreach
68
69 // Set error handler
70 set_error_handler('__errorHandler');
71
72 // Disable block-mode by default
73 enableBlockMode(false);
74
75 // Init error handler
76 initErrorHandler();
77
78 // Init request
79 initRequest();
80
81 // Init userid
82 initMemberId();
83
84 // Set important header_sent
85 if (!isset($GLOBALS['__header_sent'])) {
86         $GLOBALS['__header_sent'] = '0';
87 } // END - if
88
89 // Init fatal messages
90 initFatalMessages();
91
92 // Init repository data sub-system
93 initRepositoryData();
94
95 // Enable HTML templates by default
96 enableTemplateHtml();
97
98 // Are we in installation phase?
99 if ((!isInstalling()) && (!isInstallationPhase())) {
100         // Load configuration file(s) here
101         loadIncludeOnce('inc/load_config.php');
102
103         // Load database layer here
104         loadIncludeOnce('inc/db/lib.php');
105
106         // Init message system
107         initMessages();
108
109         // CSS array
110         initExtensionCssFiles();
111
112         if ((!empty($GLOBALS['mysql']['host'])) && (!empty($GLOBALS['mysql']['login'])) && (!empty($GLOBALS['mysql']['dbase']))) {
113                 // Connect to DB
114                 SQL_CONNECT($GLOBALS['mysql']['host'], $GLOBALS['mysql']['login'], $GLOBALS['mysql']['password'], __FILE__, __LINE__);
115
116                 // Is the link valid?
117                 if (SQL_IS_LINK_UP()) {
118                         // Enable exit on error
119                         enableExitOnError();
120
121                         // Is it a valid resource?
122                         if (SQL_SELECT_DB($GLOBALS['mysql']['dbase'], __FILE__, __LINE__) === true) {
123                                 // Set database name (required for ext-optimize and ifSqlTableExists())
124                                 setConfigEntry('__DB_NAME', $GLOBALS['mysql']['dbase']);
125
126                                 // Remove MySQL array from namespace
127                                 unset($GLOBALS['mysql']);
128
129                                 // Load cache
130                                 loadIncludeOnce('inc/load_cache.php');
131                         } else {
132                                 // Wrong database?
133                                 reportBug(__FILE__, __LINE__, 'Wrong database selected.');
134                         }
135                 } else {
136                         // No link to database!
137                         reportBug(__FILE__, __LINE__, 'Database link is not yet up.');
138                 }
139         } else {
140                 // Maybe you forgot to enter your database login?
141                 reportBug(__FILE__, __LINE__, 'Database login is missing.');
142         }
143 } else {
144         // Default output is 'direct' for HTML output
145         setConfigEntry('OUTPUT_MODE', 'direct');
146
147         // This hack prevents a backtrace in CSS output
148         if (isCssOutputMode()) {
149                 // Problem with config so set output mode
150                 setConfigEntry('OUTPUT_MODE', 'render');
151         } // END - if
152
153         // CFG: DATABASE-TYPE
154         setConfigEntry('_DB_TYPE', 'mysql3');
155
156         // Load database layer here
157         loadIncludeOnce('inc/db/lib.php');
158
159         // Init message system
160         initMessages();
161
162         // Include more
163         foreach (array('databases', 'session', 'versions', 'install-functions', 'load_config', 'load_cache') as $inc) {
164                 // Load the include
165                 loadIncludeOnce('inc/' . $inc . '.php');
166         } // END - foreach
167
168         // Init installer
169         initInstaller();
170
171         // Check whether we are in installation routine
172         if ((!isInstalling()) && (!isCssOutputMode()) && (!isRawOutputMode())) {
173                 // Redirect to the URL
174                 redirectToUrl('install.php');
175         } // END - if
176 }
177
178 // Handle fatal errors
179 runFilterChain('handle_fatal_errors');
180
181 // [EOF]
182 ?>