<?php
/*
+-----------------------------------------------------------------------------+
| $Id: lib.database.php 2009-10-12 11:26:29Z Bleakwind $
| Initialize Database
| Copyright (c) 2003-2010 Bleakwind (www.weaverdream.com)
| http://www.weaverdream.com/
| Release under the GNU Lesser General Public License Version 3 (LGPLv3):
|   http://www.gnu.org/licenses/lgpl.html
+-----------------------------------------------------------------------------+
*/

include_once './lib/adodb/adodb.inc.php';

// Initialize Database
$ADODB_CACHE_DIR = "./cache/adodb/";
if (!file_exists($ADODB_CACHE_DIR)) { func::make_dir($ADODB_CACHE_DIR); }
$db = &ADONewConnection(CONFIG_DB_TYPE);
$result_connect = @$db->NConnect(CONFIG_DB_HOSTNAME, CONFIG_DB_USERNAME, CONFIG_DB_PASSWORD, CONFIG_DB_DATABASE);
if (!$result_connect) {
    printf("<div style='font-family:sans-serif;font-size: 11px;'><b>Weaverdream info:</b> MySQL Error</div>\n");
    printf("<div style='width:600px;padding: 3px;background-color:#D6DFF7;border:#1151BF 1px solid;font-family:sans-serif;font-size: 11px;'>\n");
    printf("<b>Page:</b> ".$_SERVER['PHP_SELF']."<br>\n");
    printf("<b>Database error:</b> %s <br>\n", "Db Connect Error!");
    printf("<b>MySQL Error(Error):</b> %s <br>\n", $db->ErrorMsg());
    printf("<b>MySQL Error(Errno):</b> %s <br>\n", $db->ErrorNo());
    printf("</div>\n");
    printf("<div style='font-family:sans-serif;font-size: 11px;'>You can try to <a href='javascript:location.reload()' target='_self'><font color='#1151BF' style='text-decoration:none;'>refresh</font></a> the page, if this doesn't fix the error, please contact <font color='#1151BF'>".CONFIG_ADMINEMAIL."</font> and report the error message.</div>\n");
    exit("<div style='font-family:sans-serif;font-size: 11px;'>MySQL halted.</div>\n");
}
$db->Execute("SET NAMES '".CONFIG_DB_CHARSET."'");
?>
