Save a configuration file
static public writeConfig ( $name, $content ) : boolean | ||
$name | string config file name | |
$content | string config file content | |
리턴 | boolean |
/** * Create slave DB configuration file * * @param host the slave DB host(s) * @param user the slave DB user * @param password the slave DB password * @param DBname the name of the slave DB * * @return boolean for success **/ static function createSlaveConnectionFile($host, $user, $password, $DBname) { $DB_str = "<?php \n class DBSlave extends DBmysql { \n var \$slave = true; \n var \$dbhost = "; $host = trim($host); if (strpos($host, ' ')) { $hosts = explode(' ', $host); $first = true; foreach ($hosts as $host) { if (!empty($host)) { $DB_str .= ($first ? "array('" : ",'") . $host . "'"; $first = false; } } if ($first) { // no host configured return false; } $DB_str .= ");\n"; } else { $DB_str .= "'{$host}';\n"; } $DB_str .= " var \$dbuser = '******'; \n var \$dbpassword= '******'; \n var \$dbdefault = '" . $DBname . "'; \n } \n ?>"; return Toolbox::writeConfig('config_db_slave.php', $DB_str); }
function create_conn_file($host, $user, $password, $DBname) { global $CFG_GLPI; $DB_str = "<?php\n class DB extends DBmysql {\n \n var \$dbhost = '" . $host . "';\n \n var \$dbuser \t= '" . $user . "';\n \n var \$dbpassword= '******';\n \n var \$dbdefault\t= '" . $DBname . "';\n \n } \n?>"; return Toolbox::writeConfig('config_db.php', $DB_str); }