function doInstall() { global $mysql_usePrefix, $mysql_prefix, $weblog_ping; // 0. put all POST-vars into vars $mysql_host = postVar('mySQL_host'); $mysql_user = postVar('mySQL_user'); $mysql_password = postVar('mySQL_password'); $mysql_database = postVar('mySQL_database'); $mysql_create = postVar('mySQL_create'); $mysql_usePrefix = postVar('mySQL_usePrefix'); $mysql_prefix = postVar('mySQL_tablePrefix'); $config_indexurl = postVar('IndexURL'); $config_adminurl = postVar('AdminURL'); $config_adminpath = postVar('AdminPath'); $config_mediaurl = postVar('MediaURL'); $config_skinsurl = postVar('SkinsURL'); $config_pluginurl = postVar('PluginURL'); $config_actionurl = postVar('ActionURL'); $config_mediapath = postVar('MediaPath'); $config_skinspath = postVar('SkinsPath'); $user_name = postVar('User_name'); $user_realname = postVar('User_realname'); $user_password = postVar('User_password'); $user_password2 = postVar('User_password2'); $user_email = postVar('User_email'); $blog_name = postVar('Blog_name'); $blog_shortname = postVar('Blog_shortname'); $charset = postVar('charset'); $config_adminemail = $user_email; $config_sitename = $blog_name; $weblog_ping = postVar('Weblog_ping'); $_POST = array(); $config_indexurl = replaceDoubleBackslash($config_indexurl); $config_adminurl = replaceDoubleBackslash($config_adminurl); $config_mediaurl = replaceDoubleBackslash($config_mediaurl); $config_skinsurl = replaceDoubleBackslash($config_skinsurl); $config_pluginurl = replaceDoubleBackslash($config_pluginurl); $config_actionurl = replaceDoubleBackslash($config_actionurl); $config_adminpath = replaceDoubleBackslash($config_adminpath); $config_skinspath = replaceDoubleBackslash($config_skinspath); $config_mediapath = replaceDoubleBackslash($config_mediapath); /** * Include and initialize multibyte functions as a replacement for mbstring extension * if mbstring extension is not loaded. * Jan.28, 2011. Japanese Package Release Team */ if (!function_exists('mb_convert_encoding')) { global $mbemu_internals; include_once $config_adminpath . 'libs/mb_emulator/mb-emulator.php'; } if (function_exists('date_default_timezone_set')) { @date_default_timezone_set(function_exists('date_default_timezone_get') ? @date_default_timezone_get() : 'UTC'); } if ($charset == 'ujis') { define('_CHARSET', 'EUC-JP'); $config_sitename = mb_convert_encoding($config_sitename, _CHARSET, 'UTF-8'); $user_realname = mb_convert_encoding($user_realname, _CHARSET, 'UTF-8'); $blog_name = mb_convert_encoding($blog_name, _CHARSET, 'UTF-8'); } else { define('_CHARSET', 'UTF-8'); } // 1. check all the data $errors = array(); if (!$mysql_database) { array_push($errors, _ERROR2); } if ($mysql_usePrefix == 1 && strlen($mysql_prefix) == 0) { array_push($errors, _ERROR3); } if ($mysql_usePrefix == 1 && !preg_match('#^[a-zA-Z0-9_]+$#', $mysql_prefix)) { array_push($errors, _ERROR4); } // TODO: add action.php check if (!endsWithSlash($config_indexurl) || !endsWithSlash($config_adminurl) || !endsWithSlash($config_mediaurl) || !endsWithSlash($config_pluginurl) || !endsWithSlash($config_skinsurl)) { array_push($errors, _ERROR5); } if (!endsWithSlash($config_adminpath)) { array_push($errors, _ERROR6); } if (!endsWithSlash($config_mediapath)) { array_push($errors, _ERROR7); } if (!endsWithSlash($config_skinspath)) { array_push($errors, _ERROR8); } if (!is_dir($config_adminpath)) { array_push($errors, _ERROR9); } if (!_isValidMailAddress($user_email)) { array_push($errors, _ERROR10); } if (!_isValidDisplayName($user_name)) { array_push($errors, _ERROR11); } if (!$user_password || !$user_password2) { array_push($errors, _ERROR12); } if ($user_password != $user_password2) { array_push($errors, _ERROR13); } if (!_isValidShortName($blog_shortname)) { array_push($errors, _ERROR14); } if (sizeof($errors) > 0) { showErrorMessages($errors); } // 2. try to log in to mySQL global $MYSQL_CONN; // this will need to be changed if we ever allow $MYSQL_CONN = @sql_connect_args($mysql_host, $mysql_user, $mysql_password); if ($MYSQL_CONN == false) { _doError(_ERROR15 . ': ' . sql_error()); } // 3. try to create database (if needed) $mySqlVer = implode('.', array_map('intval', explode('.', sql_get_server_info()))); $collation = $charset == 'utf8' ? 'utf8_general_ci' : 'ujis_japanese_ci'; if ($mysql_create == 1) { $sql = 'CREATE DATABASE ' . $mysql_database; // <add for garble measure> if (version_compare($mySqlVer, '4.1.0', '>=')) { $sql .= ' DEFAULT CHARACTER SET ' . $charset . ' COLLATE ' . $collation; } // </add for garble measure>*/ sql_query($sql, $MYSQL_CONN) or _doError(_ERROR16 . ': ' . sql_error($MYSQL_CONN)); } // 4. try to select database sql_select_db($mysql_database, $MYSQL_CONN) or _doError(_ERROR17); /* * 4.5. set character set to this database in MySQL server * This processing is added by Nucleus CMS Japanese Package Release Team as of Mar.30, 2011 */ sql_set_charset_jp($charset); // 5. execute queries $filename = 'install.sql'; $fd = fopen($filename, 'r'); $queries = fread($fd, filesize($filename)); fclose($fd); $queries = split("(;\n|;\r)", $queries); $aTableNames = array('nucleus_actionlog', 'nucleus_ban', 'nucleus_blog', 'nucleus_category', 'nucleus_comment', 'nucleus_config', 'nucleus_item', 'nucleus_karma', 'nucleus_member', 'nucleus_plugin', 'nucleus_skin', 'nucleus_template', 'nucleus_team', 'nucleus_activation', 'nucleus_tickets'); // these are unneeded (one of the replacements above takes care of them) // 'nucleus_plugin_event', // 'nucleus_plugin_option', // 'nucleus_plugin_option_desc', // 'nucleus_skin_desc', // 'nucleus_template_desc', $aTableNamesPrefixed = array($mysql_prefix . 'nucleus_actionlog', $mysql_prefix . 'nucleus_ban', $mysql_prefix . 'nucleus_blog', $mysql_prefix . 'nucleus_category', $mysql_prefix . 'nucleus_comment', $mysql_prefix . 'nucleus_config', $mysql_prefix . 'nucleus_item', $mysql_prefix . 'nucleus_karma', $mysql_prefix . 'nucleus_member', $mysql_prefix . 'nucleus_plugin', $mysql_prefix . 'nucleus_skin', $mysql_prefix . 'nucleus_template', $mysql_prefix . 'nucleus_team', $mysql_prefix . 'nucleus_activation', $mysql_prefix . 'nucleus_tickets'); // these are unneeded (one of the replacements above takes care of them) // $mysql_prefix . 'nucleus_plugin_event', // $mysql_prefix . 'nucleus_plugin_option', // $mysql_prefix . 'nucleus_plugin_option_desc', // $mysql_prefix . 'nucleus_skin_desc', // $mysql_prefix . 'nucleus_template_desc', $count = count($queries); for ($idx = 0; $idx < $count; $idx++) { $query = trim($queries[$idx]); // echo "QUERY = " . htmlspecialchars($query) . "<p>"; if ($query) { if ($mysql_usePrefix == 1) { $query = str_replace($aTableNames, $aTableNamesPrefixed, $query); } // <add for garble measure> if ($mysql_create != 1 && strpos($query, 'CREATE TABLE') === 0 && version_compare($mySqlVer, '4.1.0', '>=')) { $query .= ' DEFAULT CHARACTER SET ' . $charset . ' COLLATE ' . $collation; } // </add for garble measure>*/ sql_query($query, $MYSQL_CONN) or _doError(_ERROR30 . ' (' . htmlspecialchars($query) . '): ' . sql_error($MYSQL_CONN)); } } // 5a make first post if (strtoupper(_CHARSET) != 'UTF-8') { $itm_title = mb_convert_encoding(_1ST_POST_TITLE, _CHARSET, 'UTF-8'); $itm_body = mb_convert_encoding(_1ST_POST, _CHARSET, 'UTF-8'); $itm_more = mb_convert_encoding(_1ST_POST2, _CHARSET, 'UTF-8'); } else { $itm_title = _1ST_POST_TITLE; $itm_body = _1ST_POST; $itm_more = _1ST_POST2; } $newpost = "INSERT INTO " . tableName('nucleus_item') . " VALUES (" . "1, " . "'" . $itm_title . "'," . " '" . $itm_body . "'," . " '" . $itm_more . "'," . " 1, 1, '2005-08-15 11:04:26', 0, 0, 0, 1, 0, 1);"; sql_query($newpost, $MYSQL_CONN) or _doError(_ERROR18 . ' (' . htmlspecialchars($newpost) . '): ' . sql_error($MYSQL_CONN)); // 6. update global settings updateConfig('IndexURL', $config_indexurl); updateConfig('AdminURL', $config_adminurl); updateConfig('MediaURL', $config_mediaurl); updateConfig('SkinsURL', $config_skinsurl); updateConfig('PluginURL', $config_pluginurl); updateConfig('ActionURL', $config_actionurl); updateConfig('AdminEmail', $config_adminemail); updateConfig('SiteName', $config_sitename); if ($charset == 'ujis') { updateConfig('Language', 'japanese-euc'); } // 7. update GOD member $query = 'UPDATE ' . tableName('nucleus_member') . " SET mname\t = '" . addslashes($user_name) . "'," . " mrealname\t = '" . addslashes($user_realname) . "'," . " mpassword\t = '" . md5(addslashes($user_password)) . "'," . " murl\t\t = '" . addslashes($config_indexurl) . "'," . " memail\t\t= '" . addslashes($user_email) . "'," . " madmin\t\t= 1," . " mcanlogin\t = 1" . " WHERE" . " mnumber\t = 1"; sql_query($query, $MYSQL_CONN) or _doError(_ERROR19 . ': ' . sql_error($MYSQL_CONN)); // 8. update weblog settings $query = 'UPDATE ' . tableName('nucleus_blog') . " SET bname = '" . addslashes($blog_name) . "'," . " bshortname = '" . addslashes($blog_shortname) . "'," . " burl\t = '" . addslashes($config_indexurl) . "'" . " WHERE" . " bnumber\t= 1"; sql_query($query, $MYSQL_CONN) or _doError(_ERROR20 . ': ' . sql_error($MYSQL_CONN)); // 8-2. update category settings if (strtoupper(_CHARSET) != 'UTF-8') { $cat_name = mb_convert_encoding(_GENERALCAT_NAME, _CHARSET, 'UTF-8'); $cat_desc = mb_convert_encoding(_GENERALCAT_DESC, _CHARSET, 'UTF-8'); } else { $cat_name = _GENERALCAT_NAME; $cat_desc = _GENERALCAT_DESC; } $query = 'UPDATE ' . tableName('nucleus_category') . " SET cname = '" . $cat_name . "'," . " cdesc\t = '" . $cat_desc . "'" . " WHERE" . " catid\t = 1"; sql_query($query, $MYSQL_CONN) or _doError(_ERROR20 . ': ' . sql_error($MYSQL_CONN)); // 9. update item date $query = 'UPDATE ' . tableName('nucleus_item') . " SET itime = '" . date('Y-m-d H:i:s', time()) . "'" . " WHERE inumber = 1"; sql_query($query, $MYSQL_CONN) or _doError(_ERROR21 . ': ' . sql_error($MYSQL_CONN)); global $aConfPlugsToInstall, $aConfSkinsToImport; $aSkinErrors = array(); $aPlugErrors = array(); if (count($aConfPlugsToInstall) > 0 || count($aConfSkinsToImport) > 0) { // 10. set global variables global $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_PREFIX; $MYSQL_HOST = $mysql_host; $MYSQL_USER = $mysql_user; $MYSQL_PASSWORD = $mysql_password; $MYSQL_DATABASE = $mysql_database; $MYSQL_PREFIX = $mysql_usePrefix == 1 ? $mysql_prefix : ''; global $DIR_NUCLEUS, $DIR_MEDIA, $DIR_SKINS, $DIR_PLUGINS, $DIR_LANG, $DIR_LIBS; $DIR_NUCLEUS = $config_adminpath; $DIR_MEDIA = $config_mediapath; $DIR_SKINS = $config_skinspath; $DIR_PLUGINS = $DIR_NUCLEUS . 'plugins/'; $DIR_LANG = $DIR_NUCLEUS . 'language/'; $DIR_LIBS = $DIR_NUCLEUS . 'libs/'; // close database connection (needs to be closed if we want to include globalfunctions.php) sql_close($MYSQL_CONN); $manager = ''; include_once $DIR_LIBS . 'globalfunctions.php'; // 11. install custom skins $aSkinErrors = installCustomSkins($manager); $defskinQue = 'SELECT `sdnumber` as result FROM ' . sql_table('skin_desc') . ' WHERE `sdname` = "default"'; $defSkinID = quickQuery($defskinQue); $updateQuery = 'UPDATE ' . sql_table('blog') . ' SET `bdefskin` = ' . intval($defSkinID) . ' WHERE `bnumber` = 1'; sql_query($updateQuery); $updateQuery = 'UPDATE ' . sql_table('config') . ' SET `value` = ' . intval($defSkinID) . ' WHERE `name` = "BaseSkin"'; sql_query($updateQuery); // 12. install NP_Ping, if decided if ($weblog_ping == 1) { global $aConfPlugsToInstall; array_push($aConfPlugsToInstall, "NP_Ping"); } // 13. install custom plugins $aPlugErrors = installCustomPlugs($manager); } // 14. Write config file ourselves (if possible) $bConfigWritten = 0; if (@file_exists('../config.php') && is_writable('../config.php') && ($fp = @fopen('../config.php', 'w'))) { $config_data = '<' . '?php' . "\n\n"; //$config_data .= "\n"; (extraneous, just added extra \n to previous line $config_data .= " // mySQL connection information\n"; $config_data .= " \$MYSQL_HOST\t = '" . $mysql_host . "';\n"; $config_data .= " \$MYSQL_USER\t = '" . $mysql_user . "';\n"; $config_data .= " \$MYSQL_PASSWORD = '******';\n"; $config_data .= " \$MYSQL_DATABASE = '" . $mysql_database . "';\n"; $config_data .= " \$MYSQL_PREFIX = '" . ($mysql_usePrefix == 1 ? $mysql_prefix : '') . "';\n"; $config_data .= " // new in 3.50. first element is db handler, the second is the db driver used by the handler\n"; $config_data .= " // default is \$MYSQL_HANDLER = array('mysql','');\n"; $config_data .= " //\$MYSQL_HANDLER = array('mysql','mysql');\n"; $config_data .= " //\$MYSQL_HANDLER = array('pdo','mysql');\n"; $config_data .= " \$MYSQL_HANDLER = array('" . $MYSQL_HANDLER[0] . "','" . $MYSQL_HANDLER[1] . "');\n"; $config_data .= "\n"; $config_data .= " // main nucleus directory\n"; $config_data .= " \$DIR_NUCLEUS = '" . $config_adminpath . "';\n"; $config_data .= "\n"; $config_data .= " // path to media dir\n"; $config_data .= " \$DIR_MEDIA = '" . $config_mediapath . "';\n"; $config_data .= "\n"; $config_data .= " // extra skin files for imported skins\n"; $config_data .= " \$DIR_SKINS = '" . $config_skinspath . "';\n"; $config_data .= "\n"; $config_data .= " // these dirs are normally sub dirs of the nucleus dir, but \n"; $config_data .= " // you can redefine them if you wish\n"; $config_data .= " \$DIR_PLUGINS = \$DIR_NUCLEUS . 'plugins/';\n"; $config_data .= " \$DIR_LANG\t= \$DIR_NUCLEUS . 'language/';\n"; $config_data .= " \$DIR_LIBS\t= \$DIR_NUCLEUS . 'libs/';\n"; $config_data .= "\n"; $config_data .= " // include libs\n"; $config_data .= " include(\$DIR_LIBS . 'globalfunctions.php');\n"; $config_data .= "?" . ">"; $result = @fputs($fp, $config_data, strlen($config_data)); fclose($fp); if ($result) { $bConfigWritten = 1; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title><?php echo _TITLE; ?> </title> <style>@import url('../nucleus/styles/manual.css');</style> </head> <body> <div style="text-align:center"><img src="../nucleus/styles/logo.gif" alt="<?php echo _ALT_NUCLEUS_CMS_LOGO; ?> " /></div> <!-- Nucleus logo --> <?php $aAllErrors = array_merge($aSkinErrors, $aPlugErrors); if (count($aAllErrors) > 0) { echo '<h1>' . _TITLE2 . '</h1>'; echo '<ul><li>' . implode('</li><li>', $aAllErrors) . '</li></ul>'; } if (!$bConfigWritten) { ?> <h1><?php echo _TITLE3; ?> </h1> <?php echo _TEXT10; ?> <pre><code><?php // mySQL connection information $MYSQL_HOST = '<b><?php echo $mysql_host; ?> </b>'; $MYSQL_USER = '******'; $MYSQL_PASSWORD = '******'; $MYSQL_DATABASE = '<b><?php echo $mysql_database; ?> </b>'; $MYSQL_PREFIX = '<b><?php echo $mysql_usePrefix == 1 ? $mysql_prefix : ''; ?> </b>'; // new in 3.50. first element is db handler, the second is the db driver used by the handler // default is $MYSQL_HANDLER = array('mysql',''); $MYSQL_HANDLER = array('<?php echo $MYSQL_HANDLER[0]; ?> ','<?php echo $MYSQL_HANDLER[1]; ?> '); // main nucleus directory $DIR_NUCLEUS = '<b><?php echo $config_adminpath; ?> </b>'; // path to media dir $DIR_MEDIA = '<b><?php echo $config_mediapath; ?> </b>'; // extra skin files for imported skins $DIR_SKINS = '<b><?php echo $config_skinspath; ?> </b>'; // these dirs are normally sub dirs of the nucleus dir, but // you can redefine them if you wish $DIR_PLUGINS = $DIR_NUCLEUS . 'plugins/'; $DIR_LANG = $DIR_NUCLEUS . 'language/'; $DIR_LIBS = $DIR_NUCLEUS . 'libs/'; // include libs include($DIR_LIBS . 'globalfunctions.php'); ?></code></pre> <?php echo _TEXT11; ?> <div class="note"> <?php echo _TEXT12; ?> </div> <?php } else { ?> <h1><?php echo _TITLE4; ?> </h1> <?php echo _TEXT13; ?> <?php } ?> <h1><?php echo _TITLE5; ?> </h1> <?php echo _TEXT14; ?> <ul> <li><?php echo _TEXT14_L1; ?> </li> <li><?php echo _TEXT14_L2; ?> </li> </ul> <h1><?php echo _HEADER10; ?> </h1> <?php echo _TEXT15; ?> <ul> <li><?php echo _TEXT15_L1; ?> </li> <li><?php echo _TEXT15_L2; ?> </li> <li><?php echo _TEXT15_L3; ?> </li> </ul> <?php echo _TEXT16; ?> <h1><?php echo _HEADER11; ?> </h1> <p><?php echo _TEXT16_H; ?> <ul> <li><a href="<?php echo $config_adminurl; ?> "><?php echo _TEXT16_L1; ?> </a></li> <li><a href="<?php echo $config_indexurl; ?> "><?php echo _TEXT16_L2; ?> </a></li> </ul> </p> </body> </html> <?php }
/** * Connects to mysql server */ function sql_connect() { global $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_CONN; $MYSQL_CONN = @mysql_connect($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD) or startUpError('<p>Could not connect to MySQL database.</p>', 'Connect Error'); mysql_select_db($MYSQL_DATABASE) or startUpError('<p>Could not select database: ' . mysql_error() . '</p>', 'Connect Error'); // <add for garble measure> if (defined(_CHARSET)) { $charset = _CHARSET; } else { $resource = sql_query("show variables LIKE 'character_set_database'"); $fetchDat = sql_fetch_assoc($resource); $charset = $fetchDat['Value']; // in trouble of encoding,uncomment the following line. // $charset = "ujis"; // $charset = "utf8"; } sql_set_charset_jp($charset); // </add for garble measure>*/ return $MYSQL_CONN; }
setcookie($CONF['CookiePrefix'] . 'lastVisit', '', time() - 2592000, $CONF['CookiePath'], $CONF['CookieDomain'], $CONF['CookieSecure']); } } // read language file, only after user has been initialized $language = getLanguageName(); # replaced ereg_replace() below with preg_replace(). ereg* functions are deprecated in PHP 5.3.0 # original ereg_replace: ereg_replace( '[\\|/]', '', $language) . '.php') # important note that '\' must be matched with '\\\\' in preg* expressions include $DIR_LANG . preg_replace('#[\\\\|/]#', '', $language) . '.php'; // check if valid charset if (!encoding_check(false, false, _CHARSET)) { foreach (array($_GET, $_POST) as $input) { array_walk($input, 'encoding_check'); } } sql_set_charset_jp(_CHARSET); /* Backed out for now: See http://forum.nucleuscms.org/viewtopic.php?t=3684 for details // To remove after v2.5 is released and language files have been updated. // Including this makes sure that language files for v2.5beta can still be used for v2.5final // without having weird _SETTINGS_EXTAUTH string showing up in the admin area. if (!defined('_MEMBERS_BYPASS')) { define('_SETTINGS_EXTAUTH', 'Enable External Authentication'); define('_WARNING_EXTAUTH', 'Warning: Enable only if needed.'); define('_MEMBERS_BYPASS', 'Use External Authentication'); } */ // make sure the archivetype skinvar keeps working when _ARCHIVETYPE_XXX not defined if (!defined('_ARCHIVETYPE_MONTH')) { define('_ARCHIVETYPE_DAY', 'day');
/** * Connects to mysql server */ function sql_connect() { global $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_CONN, $MYSQL_HANDLER, $SQL_DBH; $SQL_DBH = NULL; try { if (strpos($MYSQL_HOST, ':') === false) { $host = $MYSQL_HOST; $port = ''; } else { list($host, $port) = explode(":", $MYSQL_HOST); if (isset($port)) { $portnum = $port; $port = ';port=' . trim($port); } else { $port = ''; $portnum = ''; } } switch ($MYSQL_HANDLER[1]) { case 'sybase': case 'dblib': if (is_numeric($portnum)) { $port = ':' . intval($portnum); } else { $port = ''; } $SQL_DBH = new PDO($MYSQL_HANDLER[1] . ':host=' . $host . $port . ';dbname=' . $MYSQL_DATABASE, $MYSQL_USER, $MYSQL_PASSWORD); break; case 'mssql': if (is_numeric($portnum)) { $port = ',' . intval($portnum); } else { $port = ''; } $SQL_DBH = new PDO($MYSQL_HANDLER[1] . ':host=' . $host . $port . ';dbname=' . $MYSQL_DATABASE, $MYSQL_USER, $MYSQL_PASSWORD); break; case 'oci': if (is_numeric($portnum)) { $port = ':' . intval($portnum); } else { $port = ''; } $SQL_DBH = new PDO($MYSQL_HANDLER[1] . ':dbname=//' . $host . $port . '/' . $MYSQL_DATABASE, $MYSQL_USER, $MYSQL_PASSWORD); break; case 'odbc': if (is_numeric($portnum)) { $port = ';PORT=' . intval($portnum); } else { $port = ''; } $SQL_DBH = new PDO($MYSQL_HANDLER[1] . ':DRIVER={IBM DB2 ODBC DRIVER};HOSTNAME=' . $host . $port . ';DATABASE=' . $MYSQL_DATABASE . ';PROTOCOL=TCPIP;UID=' . $MYSQL_USER . ';PWD=' . $MYSQL_PASSWORD); break; case 'pgsql': if (is_numeric($portnum)) { $port = ';port=' . intval($portnum); } else { $port = ''; } $SQL_DBH = new PDO($MYSQL_HANDLER[1] . ':host=' . $host . $port . ';dbname=' . $MYSQL_DATABASE, $MYSQL_USER, $MYSQL_PASSWORD); break; case 'sqlite': case 'sqlite2': if (is_numeric($portnum)) { $port = ':' . intval($portnum); } else { $port = ''; } $SQL_DBH = new PDO($MYSQL_HANDLER[1] . ':' . $MYSQL_DATABASE, $MYSQL_USER, $MYSQL_PASSWORD); break; default: //mysql $SQL_DBH = new PDO($MYSQL_HANDLER[1] . ':host=' . $host . $port . ';dbname=' . $MYSQL_DATABASE, $MYSQL_USER, $MYSQL_PASSWORD); break; } //$SQL_DBH = new PDO($MYSQL_HANDLER[1].':host='.$host.$port.';dbname='.$MYSQL_DATABASE, $MYSQL_USER, $MYSQL_PASSWORD); // <add for garble measure> if (strpos($MYSQL_HANDLER[1], 'mysql') === 0) { if (defined(_CHARSET)) { $charset = _CHARSET; } else { $resource = $SQL_DBH->query("show variables LIKE 'character_set_database'"); $resource->bindColumn('Value', $charset); $resource->fetchAll(); // in trouble of encoding,uncomment the following line. // $charset = "ujis"; // $charset = "utf8"; } sql_set_charset_jp($charset); } // </add for garble measure>*/ } catch (PDOException $e) { $SQL_DBH = NULL; startUpError('<p>a2 Error!: ' . $e->getMessage() . '</p>', 'Connect Error'); } // echo '<hr />DBH: '.print_r($SQL_DBH,true).'<hr />'; $MYSQL_CONN &= $SQL_DBH; return $SQL_DBH; }