<?php require '../classes/AutoLoad.php'; date_default_timezone_set('Europe/Madrid'); $mysql = new mysqli(Constan::SERVER, Constan::DBUSER, Constan::DBPASSWORD); $res = $mysql->query(FileManager::read('sql/sql.sql')); $mysql->change_user(Constan::DBUSER, Constan::DBPASSWORD, Constan::DATABASE); $ms = scandir('../modules'); foreach ($ms as $key => $value) { if ($value !== '.' && $value !== '..' && $value !== 'index.php') { if (is_dir('../modules/' . $value)) { $files = scandir('../modules/' . $value . '/sql'); foreach ($files as $file) { if ($file !== '.' && $file !== '..') { $mysql->query(FileManager::read('../modules/' . $value . '/sql/' . $file)); } } } } } $mysql->close(); header('Location:../modules/');
/** * Change currently selected database. * @param string $databaseName New database name. * @return boolean Returns <b>TRUE</b> on success or <b>FALSE</b> on failure. */ public function changeDatabase($databaseName) { if (parent::change_user($this->userName, $this->userPassword, $databaseName)) { $this->databaseName = $databaseName; return TRUE; } return FALSE; }
} elseif (strlen($_POST["DatabaseWriterHost"]) > 64) { $pageErrors[] = "Database Writer Connectivity Host must not be greater than 64 characters."; } if ($_POST["DatabaseWriterPass"] == "") { $pageErrors[] = "Database Writer Password must not be empty."; } elseif (strlen($_POST["DatabaseWriterPass"]) > 20) { $pageErrors[] = "Database Writer Password must not be greater than 20 characters."; } if (count($pageErrors) == 0) { $mySQLiConn = new mysqli("p:" . $mysqlHost, $mysqlAdminUser, $mysqlAdminPass, "mysql", $mysqlPort); if (!$mySQLiConn->connect_error) { // -- create database $createDatabase = "CREATE DATABASE `" . $databaseName . "` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin"; if ($mySQLiConn->query($createDatabase)) { $pageSuccess[] = "Successfully created database `" . $databaseName . "`."; $mySQLiConn->change_user($mysqlAdminUser, $mysqlAdminPass, $databaseName); if (!$mySQLiConn->connect_error) { // -- create table `hotlaps` if ($mySQLiConn->query($createTableHotlaps)) { $pageSuccess[] = "Successfully created table `hotlaps`."; } else { $pageErrors[] = "Error creating table `hotlaps`: (" . $mySQLiConn->error . ")"; } // -- create table `racelaps` if ($mySQLiConn->query($createTableRacelaps)) { $pageSuccess[] = "Successfully created table `racelaps`."; } else { $pageErrors[] = "Error creating table `racelaps`: (" . $mySQLiConn->error . ")"; } // -- create table `sessioninfos` if ($mySQLiConn->query($createTableSessioninfos)) {
/** * (non-PHPdoc) * @see mysqli::change_user() * @return bool */ public function change_user($user, $password, $database = NULL) { if (isset($database)) { $this->setDb($database); } $this->setUsername($user); $this->setPassword($password); return parent::change_user($this->getUsername(), $this->password, $this->getDb()); }
function mysqliConnect($db = null) { $db = $db ? $db : $_SESSION['base_datos']->nombrebd; $mysqli = new mysqli(BD_HOST, BD_SP_USUARIO, BD_SP_CLAVE, $db); if (mysqli_connect_errno()) { $error_db['TIPO ERROR'] = "LA BASE DE DATOS NO SE ENCUENTRA DISPONIBLE, ERROR DE CONEXIÓN"; $error_db['MYSQLI ERROR'] = mysqli_connect_error(); dpr($error_db); exit; } $mysqli->change_user(BD_SP_USUARIO, BD_SP_CLAVE, $db); return $mysqli; }