/** * Install TCExam database. * @param $db_type (string) database type (MySQL) * @param $db_host (string) database host * @param $db_port (string) database port number * @param $db_user (string) database user * @param $db_password (string) database password * @param $database_name (string) database name * @param $table_prefix (string) prefix for tables * @param $drop_database (boolean) if true drop existing database * @param $create_new (boolean) if true creates new database * @param $progress_log (string) log file name * @return boolean True in case of success, False otherwise. */ function F_install_database($db_type, $db_host, $db_port, $db_user, $db_password, $database_name, $table_prefix, $drop_database, $create_new, $progress_log) { ini_set('memory_limit', '256M'); define('K_DATABASE_TYPE', $db_type); // database type (for Database Abstraction Layer) // Load the Database Abstraction Layer for selected DATABASE type switch (K_DATABASE_TYPE) { case 'ORACLE': require_once '../shared/code/tce_db_dal_oracle.php'; break; case 'POSTGRESQL': require_once '../shared/code/tce_db_dal_postgresql.php'; break; case 'MYSQL': require_once '../shared/code/tce_db_dal_mysql.php'; break; default: return false; } echo "\n" . '<li>create or replace database and get connection........'; error_log(' create or replace database and get connection' . "\n", 3, $progress_log); //log info if ($db = F_create_database(K_DATABASE_TYPE, $db_host, $db_port, $db_user, $db_password, $database_name, $table_prefix, $drop_database, $create_new)) { //create database if not exist echo '<span style="color:#008000">[OK]</span></li>'; echo "\n" . '<li>create database tables..........'; error_log(' [START] create database tables' . "\n", 3, $progress_log); //log info // process structure sql file if (F_execute_sql_queries($db, strtolower(K_DATABASE_TYPE) . '_db_structure.sql', 'tce_', $table_prefix, $progress_log)) { echo '<span style="color:#008000">[OK]</span></li>'; error_log(' [END:OK] create database tables' . "\n", 3, $progress_log); //log info echo "\n" . '<li>fill tables with default data...'; error_log(' [START] fill tables with default data' . "\n", 3, $progress_log); //log info // process data sql file if (F_execute_sql_queries($db, 'db_data.sql', 'tce_', $table_prefix, $progress_log)) { echo '<span style="color:#008000">[OK]</span></li>'; error_log(' [END:OK] fill tables with default data' . "\n", 3, $progress_log); //log info } else { echo '<span style="color:#CC0000">[ERROR ' . F_db_error() . ']</span></li>'; error_log(' [END:ERROR] fill tables with default data: ' . F_db_error() . "\n", 3, $progress_log); //log info return false; } } else { echo '<span style="color:#CC0000">[ERROR ' . F_db_error() . ']</span></li>'; error_log(' [END:ERROR] create database tables: ' . F_db_error() . "\n", 3, $progress_log); //log info return false; } } else { echo '<span style="color:#CC0000">[ERROR: ' . F_db_error() . ']</span></li>'; error_log(' [END:ERROR] could not connect to database: ' . F_db_error() . "\n", 3, $progress_log); //log info return false; } flush(); return true; }
// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. // // Additionally, you can't remove, move or hide the original TCExam logo, // copyrights statements and links to Tecnick.com and TCExam websites. // // See LICENSE.TXT file for more information. //============================================================+ /** * @file * Open a connection to a MySQL Server and select a database. * @package com.tecnick.tcexam.shared * @author Nicola Asuni * @since 2001-09-02 */ /** */ require_once '../../shared/code/tce_db_dal.php'; // Database Abstraction Layer for selected DATABASE type if (!($db = @F_db_connect(K_DATABASE_HOST, K_DATABASE_PORT, K_DATABASE_USER_NAME, K_DATABASE_USER_PASSWORD, K_DATABASE_NAME))) { die('<h2>' . F_db_error() . '</h2>'); } //============================================================+ // END OF FILE //============================================================+
/** * Print the database error message. * @param $exit (bool) if true output a message and terminate the current script [default = true]. */ function F_display_db_error($exit = true) { global $db; $messagetype = 'ERROR'; $messagetoprint = F_db_error($db); F_print_error($messagetype, $messagetoprint, $exit); }