我已经使此函数从表单中获取值并覆盖config / database.php。
function configure_database() {
// write database.php
$data_db = file_get_contents('./uploads/database.php');
// session_start();
$data_db = str_replace('%DATABASE%', $_SESSION['dbname'], $data_db);
$data_db = str_replace('%USERNAME%', $_SESSION['username'], $data_db);
$data_db = str_replace('%PASSWORD%', $_SESSION['password'], $data_db);
$data_db = str_replace('%HOSTNAME%', $_SESSION['hostname'], $data_db);
file_put_contents('./application/config/database.php', $data_db);
$this->run_blank_sql();
}
并成功overwrites
config/database.php
。在function
的最后,我写了$this->run_blank_sql();
,它调用了run_blank_sql()
,我已经写了这个function
以在SQL
中运行uploads
目录。
function run_blank_sql() {
$this->load->database();
// Set line to collect lines that wrap
$templine = '';
// Read in entire file
$lines = file('./uploads/install.sql');
// Loop through each line
foreach ($lines as $line) {
// Skip it if it's a comment
if (substr($line, 0, 2) == '--' || $line == '')
continue;
// Add this line to the current templine we are creating
$templine .= $line;
// If it has a semicolon at the end, it's the end of the query so can process this templine
if (substr(trim($line), -1, 1) == ';') {
// Perform the query
$this->db->query($templine);
// Reset temp variable to empty
$templine = '';
}
}
}
但这给了我这个错误。
configure_database()
成功覆盖了这些值。
'hostname' => '%HOSTNAME%',
'username' => '%USERNAME%',
'password' => '%PASSWORD%',
'database' => '%DATABASE%',
'dbdriver' => 'mysqli',
收件人
'hostname' => 'localhost',
'username' => 'root',
'password' => *****,
'database' => 'studentPortal',
'dbdriver' => 'mysqli',