I am encountering a problem with load data function of mysql, this is that it gives me an error whenever I try to execute the code as follows. Any help with this would be humbled and appreciated (: Thank you
Before Debugging:
<?php
ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
ini_set('max_execution_time',0);
ini_set('upload_max_filesize', '50M');
ini_set('post_max_size', '50M');
ini_set('max_input_time', 0);
ini_set("memory_limit", "-1");
set_time_limit(0);
$ip = getenv('REMOTE_ADDR');
$conn=mysqli_connect("somehost","someusr","somepw", "somedb") or die("Could not connect");
if(isset($_POST["submit_file"]))
{
$op = $_POST['op'];
$month = $_POST['month'];
$year = $_POST['year'];
chmod($file["tmp_name"], 0444);
$file = $_FILES["file"]["tmp_name"];
$file_open = fopen($file,"r");
while(($csv = fgetcsv($file_open,1000, ",")) !== false)
{
$ct = $csv[0];
$ts = $csv[1];
$cd = $csv[2];
$pc = $csv[3];
$lt = $csv[4];
$nt = $csv[5];
$xp = $csv[6];
$fn = $csv[7];
$sn = $csv[8];
$ds = $csv[9];
$pp = $csv[10];
$sql="
load data local infile '$file' replace into table anew fields terminated by ',' lines terminated by '\n' (`ct`, `ts`, `cd`, `pc`, `lt`, `nt`, `xp`, `fn`, `sn`, `ds`, `pp`, `uploadedby`);
";
$result=mysqli_query($conn, $sql);
if($result){
echo "<script type=\"text/javascript\">alert(\"success\");window.location.href = '/insights/datauploader/';</script>";
}
else{
echo "<script type=\"text/javascript\">alert(\"failure" . $mysqli->error . "\");window.location.href = '/insights/datauploader/';</script>";
}
}
}
?>
After Debugging:
<?php
ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
ini_set('max_execution_time',0);
ini_set('upload_max_filesize', '50M');
ini_set('post_max_size', '50M');
ini_set('max_input_time', 0);
ini_set("memory_limit", "-1");
set_time_limit(0);
$ip = getenv('REMOTE_ADDR');
$server="somehost";
$user="someuser";
$pass="somepw";
$dbname="somedb";
$conn = mysqli_init();
mysqli_options($conn, MYSQLI_OPT_LOCAL_INFILE, true);
mysqli_real_connect($conn, $server, $user, $pass, $dbname);
if(isset($_POST["submit_file"]))
{
$op = $_POST['op'];
$month = $_POST['month'];
$year = $_POST['year'];
$file = $_FILES["file"]["tmp_name"];
$file_open = fopen($file,"r");
$sql="
load data local infile '$file' replace into table anew fields terminated by ',' lines terminated by '\n' (`ct`, `ts`, `cd`, `pc`, `lt`, `nt`, `xp`, `fn`, `sn`, `ds`, `pp`) ;
" ;
$result=mysqli_query($conn, $sql);
if($result){
echo "<script type=\"text/javascript\">alert(\"success.\");window.location.href = '/insights/datauploader/';</script>";
}
else{
echo("Error description: " . mysqli_error($conn));
}
}
?>
New error is :
Can't find file 'C:WindowsTempphpB367.tmp'.