Here is a snippet of stuff that I have worked with another developer with, I am very basic in PHP and need to move across some of his code into my site.
This is part of the message that he has sent:
Next, please edit config.php. You need to supply and execute the
loadercsv.php from command line like this:$ php loadercsv.phpThis will extract data from zip file and would populate database which
already must exists.
What does this really mean? I do understand this is quite a guessing game but would love to know if someone else could interpret what he is saying?
Also, below is the code from the config.php file, just incase it is needed:
<?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);
?>
This seems to be very straight-forward:
The program
loadercsv.phpis written to open a hard-coded zip file, process its contents, and insert the data into a database. The database itself is assumed to be set up and running.The name of the zip file and the credentials for the database access are stored in a separate file,
config.php, which is presumably being included in the first file. That is, rather than providing the configuration options on the command line or in any other fashion, you simply edit theconfig.phpfile to contain the desired data.Finally, the program is simply run from the command line, with the command
php loadercsv.php.