Hello all,
I'm working on a piece of code to upload a CSV file and then import it into MySQL. The upload is working great. I've used PHPMyAdmin to insert the same CSV file before and it works beautifully. So I figured I would take their PHP generated code (PHPMyAdmin) and use it for my PHP version of the insert, but I'm running into trouble.
Here is what I have for code so far:
<?php
include("config.inc.php");
$csv=$_GET['csv'];
$csv="csv/$csv";
mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($database) or die( "Unable to select database");
$sql = 'LOAD DATA INFILE \'/tmp/phpJ8mXgn\' INTO TABLE `SYSTEMS` FIELDS TERMINATED BY \',\' ENCLOSED BY \'"\' ESCAPED BY \'\\\\\' LINES TERMINATED BY \'\\r\\n\' (`Hostname`, `IP`, `OS`, `OSRev`, `Manufacturer`, `Model`, `CPUs`, `Memory`, `Application`, `Support_Contract`, `Serial`, `Primary_Admin`, `Server_Room`, `Cabinet`, `RUs`, `Console_Server`, `Shutdown_Order`, `Bindview`, `Date_Aquired`, `Date_In_Service`, `Volts`, `Amps`, `Power_Supplies`, `Notes`)';
mysql_query($sql);
?>
I would like to use the variable $csv in place of \'/tmp/phpJ8mXgn\', which was generated by PHPMyAdmin, but I'm having a hard time making it work successfully. I've tried several variations of this and haven't had any luck.
Could anyone lend a suggestion on how to do this properly?
Thanks.
-Sys