I have a huge amount of data that is generated from a PHP script and needs to be inserted into a database. I've tried various solutions with different results, but the current solution (and the one I think should be the best) is that i generate the data into a CSV file and then inserts it into the database with the following query:
LOAD DATA LOCAL INFILE 'myfile.csv' INTO TABLE t1 FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY "'"
I'm using CodeIgniter as the PHP framework, and after the query has executed im redirected to an error page which only says
A Database Error Occurred
Error Number: 0
There is no error message or anything.
I've stepped through the code but all I can find is that mysqli_query() returns false and later on mysqli_errno() returns 0 and mysqli_error() returns an empty string.
However, the query has actually succeeded and when I look in the database i can see that all the data from the CSV file have successfully been inserted. Is this behaviour to be expected? If so, I guess I have to hack the CodeIgniter code a little, or call mysqli_query() directly instead of going through the framework.
I've also run the exact same query in MySQL Workbench, and I do not get an error message there.
I had the exact same issue, when I realized I was not connected to the database.
I was calling require_once('connect.php'), but this was the second time in the code that I used the require_once, so PHP did not pull in the connection.
Changing the require_once to require fixed this issue for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With