本文整理匯總了PHP中Install::split_sql_file方法的典型用法代碼示例。如果您正苦於以下問題:PHP Install::split_sql_file方法的具體用法?PHP Install::split_sql_file怎麽用?PHP Install::split_sql_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Install
的用法示例。
在下文中一共展示了Install::split_sql_file方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: Step3
//.........這裏部分代碼省略.........
$dbh->exec(sprintf('GRANT ALL PRIVILEGES ON `%s`.* to %s@%s IDENTIFIED BY %s', $this->new_db_name, $dbh->quote($this->new_db_user), $dbh->quote($this->new_db_host), $dbh->quote($this->new_db_pass)));
} else {
$dbh->exec(sprintf("GRANT ALL PRIVILEGES ON `%s`.* to %s@%% IDENTIFIED BY %s", $this->new_db_name, $dbh->quote($this->new_db_user), $dbh->quote($this->new_db_pass)));
}
// Flush
$dbh->exec('FLUSH PRIVILEGES');
} catch (Exception $e) {
throw new Exception(sprintf(__('Could not create a new user with the administrator details. Please check and try again. Error Message = [%s]'), $e->getMessage()));
}
// Set our DB details
$this->existing_db_host = $this->new_db_host;
$this->existing_db_user = $this->new_db_user;
$this->existing_db_pass = $this->new_db_pass;
$this->existing_db_name = $this->new_db_name;
// Close the connection
PDOConnect::close();
} else {
// Check details for a new database
if ($this->existing_db_host == '') {
throw new Exception(__('Please provide a database host. This is usually localhost.'));
}
if ($this->existing_db_user == '') {
throw new Exception(__('Please provide a user for the existing database.'));
}
if ($this->existing_db_pass == '') {
throw new Exception(__('Please provide a password for the existing database.'));
}
if ($this->existing_db_name == '') {
throw new Exception(__('Please provide a name for the existing database.'));
}
}
// Try and make a connection with this database
try {
$dbh = PDOConnect::connect($this->existing_db_host, $this->existing_db_user, $this->existing_db_pass, $this->existing_db_name);
} catch (Exception $e) {
throw new Exception(sprintf(__('Could not connect to MySQL with the administrator details. Please check and try again. Error Message = [%s]'), $e->getMessage()));
}
// We should have a database that we can access and populate with our tables.
$sql_files = array('structure.sql', 'data.sql');
$sqlStatementCount = 0;
$sql_file = '';
$sql = '';
try {
$dbh = PDOConnect::init();
foreach ($sql_files as $filename) {
$delimiter = ';';
$sql_file = @file_get_contents('install/master/' . $filename);
$sql_file = Install::remove_remarks($sql_file);
$sql_file = Install::split_sql_file($sql_file, $delimiter);
foreach ($sql_file as $sql) {
$sqlStatementCount++;
$dbh->exec($sql);
}
}
} catch (Exception $e) {
throw new Exception(sprintf(__('An error occurred populating the database. Statement number: %d. Error Message = [%s]. File = [%s]. SQL = [%s].'), $sqlStatementCount, $e->getMessage(), $sql_file, $sql));
}
// Write out a new settings.php
$fh = fopen('settings.php', 'wt');
if (!$fh) {
throw new Exception(__('Unable to write to settings.php. We already checked this was possible earlier, so something changed.'));
}
// Generate a secret key for various reasons
$secretKey = Install::gen_secret();
// Escape the password before we write it to disk
$dbh = PDOConnect::init();
$existing_db_pass = addslashes($this->existing_db_pass);
$settings = <<<END
<?php
/*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
* This file is part of Xibo - and is automatically generated by the installer
*
* You should not need to edit this file, unless your SQL connection details have changed.
*/
defined('XIBO') or die(__("Sorry, you are not allowed to directly access this page.") . "<br />" . __("Please press the back button in your browser."));
global \$dbhost;
global \$dbuser;
global \$dbpass;
global \$dbname;
\$dbhost = '{$this->existing_db_host}';
\$dbuser = '{$this->existing_db_user}';
\$dbpass = '{$existing_db_pass}';
\$dbname = '{$this->existing_db_name}';
define('SECRET_KEY', '{$secretKey}');
END;
if (!fwrite($fh, $settings)) {
throw new Exception(__('Unable to write to settings.php. We already checked this was possible earlier, so something changed.'));
}
fclose($fh);
// If we get here, we want to move on to the next step.
// This is handled by the calling function (i.e. there is no output from this call, we just reload and move on)
}
示例2: Step3
public function Step3()
{
Kit::ClassLoader('install');
set_time_limit(0);
$fault = false;
$fault_string = '';
foreach ($_POST as $key => $post) {
// $key should be like 1-2, 1-3 etc
// Split $key on - character.
$parts = explode('-', $key);
if (count($parts) == 2) {
$step_num = 'Step' . $parts[0];
include_once 'install/database/' . $parts[0] . '.php';
$response = $_SESSION[$step_num]->ValidateQuestion($parts[1], $post);
if (!$response == true) {
// The upgrade routine for this step wasn't happy.
$fault = true;
$fault_string .= $response . "<br />\n";
}
}
}
if ($fault) {
throw new Exception($fault_string);
}
$doBackup = Kit::GetParam('doBackup', $_POST, _CHECKBOX);
if ($doBackup == 0) {
throw new Exception(__('You MUST have a valid database backup to continue. Please take and verify a backup and upgrade again.'));
}
$sql_file = '';
$sql = '';
$i = 0;
// Now loop over the entire upgrade. Run the SQLs and PHP interleaved.
try {
$dbh = PDOConnect::init();
//$dbh->beginTransaction();
for ($i = $_SESSION['upgradeFrom'] + 1; $i <= $_SESSION['upgradeTo']; $i++) {
if (file_exists('install/database/' . $i . '.sql')) {
$delimiter = ';';
$sql_file = @file_get_contents('install/database/' . $i . '.sql');
$sql_file = Install::remove_remarks($sql_file);
$sql_file = Install::split_sql_file($sql_file, $delimiter);
foreach ($sql_file as $sql) {
$dbh->exec($sql);
}
}
if (file_exists('install/database/' . $i . '.php')) {
$stepName = 'Step' . $i;
if (!$_SESSION[$stepName]->Boot()) {
throw new Exception(__('Failed with %s', $stepName));
}
}
}
//$dbh->commit();
} catch (Exception $e) {
//$dbh->rollBack();
throw new Exception(sprintf(__('An error occurred running the upgrade. Please take a screen shot of this page and seek help. Statement number: %d. Error Message = [%s]. File = [%s]. SQL = [%s].'), $i, $e->getMessage(), $sql_file, $sql));
}
// Install files
Media::installAllModuleFiles();
// Delete install
if (!unlink('install.php')) {
$formFields[] = FormManager::AddMessage(__("Unable to delete install.php. Please ensure the webserver has permission to unlink this file and retry"));
}
$formFields[] = FormManager::AddMessage(__('The upgrade was a success!'));
// Return a rendered form
Theme::Set('form_fields', $formFields);
return Theme::RenderReturn('form_render');
}