All we need is an easy explanation of the problem, so here it is.
csv formatted data, i want to put the data to my existing database’s table in specific columns. I was trying to do it with
LOAD DATA INFILE... and i have even uncomment the
mysqli.allow_local_infile but still I’m getting the same error
load data local infile is forbidden check mysqli.allow_local_infile
Then, i thought to do it in another way, I just created a new database named
staging_hadiths and created only those columns which are ibn my
CSV file, and uploaded my CSV to that database. Now, I was trying to copy that database’s table data to my
real database table in specific columns like this:
SELECT hadithUrdu, urduNarrator from staging_hadiths.hadiths; UPDATE ifislam_hadiths.hadiths SET hadithUrdu=staging_hadiths.hadiths.hadithUrdu AND urduNarrator=staging_hadiths.hadiths.urduNarrator WHERE hadithNumber BETWEEN 3949 AND 4977
Data is too large, I can’t put data one by one in database. I hope you people will help me.
I have to use
where between for some reasons, so the data can insert to my real database’s table in the right order.
My staging database:
How can i achieve this?
How to solve :
I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.
If you want to update a table with data from another table, you have to join the tables. In your case, if staging "hadiths" contains only a single row, you could leave out the join, as follows:
UPDATE ifislam_hadiths.hadiths h1 inner join staging_hadiths.hadiths h2 SET h1.hadithUrdu = h2.hadithUrdu, -- AND does not comply with mysql syntax h1.urduNarrator = h2.hadiths.urduNarrator WHERE h1.hadithNumber BETWEEN 3949 AND 4977
But normally you would join the two tables so that each row from the table to be updated, corresponds to a single row from the other table.
An example from Tutorialspoint
Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂