Wpdb download data file '

I am using the wpdb class to run LOAD DATA LOCAL INFILE. It works fine and the data is inserted correctly - but it still returns 0, so the example does not show "No update". Is this the expected result based on the LOAD DATA method? If so, is there any other way to know that the process is running and was actually inserting rows?

Thank you so much!

Philip

global $wpdb;
$filename = 'file.csv';
$sql = "LOAD DATA LOCAL INFILE '" . $filename . "'
INTO TABLE Stock_Item
FIELDS TERMINATED BY ',' ENCLOSED BY '\"' ESCAPED BY '\"' LINES TERMINATED BY '\n' IGNORE 1 ROWS
(stock_item_code, stock_item_name)"; 

$result = $wpdb->query($sql);           
if ($result === false) { echo 'Query Fail'; }
if ($result === 0) { echo 'No update'; }
if ($result > 0) { echo 'Success'; }

      

+3


source to share


1 answer


I do it this way.

global $wpdb;
        $datafile= $_FILES['file']['tmp_name'];
        $file=$upload_dir['basedir'].'/'.$_FILES['file']['name'];
        $fileurl=$upload_dir['baseurl'].'/'.$_FILES['file']['name'];
        if (!move_uploaded_file(
        $_FILES['file']['tmp_name'],
        $file)) {
        print_r('Failed to move uploaded file.');
        }
        $sql="
        LOAD DATA LOCAL INFILE '".$fileurl."' INTO TABLE ".CRSSEARCH_TABLE."
        FIELDS TERMINATED BY ',' 
        LINES TERMINATED BY '\r\n'
        (ucn,name, course_number, standard, accredition,attended_course_form,attended_course_to,status,validity,location);
        ";
        $query = $wpdb->query($sql);

      



and work great for me like a charm.

+2


source







All Articles