本文整理汇总了PHP中PDOConnect::connect方法的典型用法代码示例。如果您正苦于以下问题:PHP PDOConnect::connect方法的具体用法?PHP PDOConnect::connect怎么用?PHP PDOConnect::connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PDOConnect
的用法示例。
在下文中一共展示了PDOConnect::connect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Step3
public function Step3()
{
// Have we been told to create a new database
$this->db_create = Kit::GetParam('db_create', _POST, _INT);
// Check all parameters have been specified
$this->db_admin_user = Kit::GetParam('admin_username', _POST, _PASSWORD);
$this->db_admin_pass = Kit::GetParam('admin_password', _POST, _PASSWORD);
$this->new_db_host = Kit::GetParam('host', _POST, _STRING);
$this->new_db_user = Kit::GetParam('db_username', _POST, _PASSWORD);
$this->new_db_pass = Kit::GetParam('db_password', _POST, _PASSWORD);
$this->new_db_name = Kit::GetParam('db_name', _POST, _PASSWORD);
$this->existing_db_host = Kit::GetParam('existing_host', _POST, _STRING);
$this->existing_db_user = Kit::GetParam('existing_db_username', _POST, _PASSWORD);
$this->existing_db_pass = Kit::GetParam('existing_db_password', _POST, _PASSWORD);
$this->existing_db_name = Kit::GetParam('existing_db_name', _POST, _PASSWORD);
// If an administrator user name / password has been specified then we should create a new DB
if ($this->db_create == 1) {
// Check details for a new database
if ($this->new_db_host == '') {
throw new Exception(__('Please provide a database host. This is usually localhost.'));
}
if ($this->new_db_user == '') {
throw new Exception(__('Please provide a user for the new database.'));
}
if ($this->new_db_pass == '') {
throw new Exception(__('Please provide a password for the new database.'));
}
if ($this->new_db_name == '') {
throw new Exception(__('Please provide a name for the new database.'));
}
if ($this->db_admin_user == '') {
throw new Exception(__('Please provide an admin user name.'));
}
// Try to create the new database
// Try and connect using these details and create the new database
try {
$dbh = PDOConnect::connect($this->new_db_host, $this->db_admin_user, $this->db_admin_pass);
} 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()));
}
// Try to create the new database
try {
$dbh = PDOConnect::init();
$dbh->exec(sprintf('CREATE DATABASE `%s`', $this->new_db_name));
} catch (Exception $e) {
throw new Exception(sprintf(__('Could not create a new database with the administrator details [%s]. Please check and try again. Error Message = [%s]'), $this->db_admin_user, $e->getMessage()));
}
// Try to create the new user
try {
$dbh = PDOConnect::init();
// Create the user and grant privileges
if ($this->new_db_host == 'localhost') {
$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);
//.........这里部分代码省略.........