这是我与另一位开发人员合作过的一小段内容,我在 PHP 方面非常基础,需要将他的一些代码转移到我的网站中。
这是他发送的信息的一部分:
接下来,请编辑 config.php。您需要从命令行提供并执行 loadercsv.php,如下所示:
$ php loadercsv.php
这将从 zip 文件中提取数据并填充必须存在的数据库。
这到底是什么意思?我确实知道这是一场猜谜游戏,但我很想知道其他人是否可以解释他在说什么?
此外,以下是 config.php 文件中的代码,以防万一:
<?php
// Temporary directory where data will be extracted. Must be directory, absolute path, writable.
define('DATA_DIR', '/CourseFinder/tmp');
// Location of zip file, must be readable and absoluate path.
define('ZIP_FILE', '/CourseFinder/assets/zip/ziplocation.zip');
define('DB_HOST', 'localhost');
define('DB_USER', 'removedforreasons');
define('DB_PASSWORD', 'removedforreasons');
define('DB_NAME', 'removedforreasons');
define('MAX_LINE_WIDTH', 2048);
define('CSV_SEP', ',');
define('RESULTS_PER_PAGE', 10);
/*
* List of CSV files to be loaded. These files are processed in order listed here.
* In case some file does not exists, process will break.
*
*/
/* Try to connect */
$connection = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
/* If cannot connect, simply exit. */
if (mysqli_connect_errno($connection)) {
$msg = sprintf("Cannot connect to MySQL: %s", mysqli_connect_errno($connection));
printf("ERROR: config.php - %s\n", $msg);
exit();
}
/* Function to close the connection */
function close_connection($connection_to_close)
{
mysqli_close($connection_to_close);
}
/* Register the function at shutdown. */
register_shutdown_function('close_connection', $connection);
?>