LOAD DATA INFILE PHP/MySQL

893

Good afternoon

I'm trying to use PHP to transfer data from a CSV file into a MySQL Database. The code I have so far is:

$insert_query = "
    LOAD DATA LOCAL INFILE 'sample.csv'
    INTO table tblUncovered
    FIELDS TERMINATED BY ','
    LINES TERMINATED BY '\n'
    (headcode, booked);
    "

if (!mysqli_query($insert_query, $conn)) {
    echo "Can't insert student record : " . mysql_error($conn);
    } 
    else {
    echo "You have successfully insert records into student table";
    }

Unfortunately, it doesn't seem to be working. If I comment out the last bit (If mysql_query onwards) the page will load, albeit do nothing. But when I include those lines, all I get is that 'This page isn't working'.

I've even tried using a file with just two rows and two fields and it won't have it.

Any ideas why?

Thanks Chris

People are also looking for solutions to the problem: html - Print php output in pop window on submitting the form

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.