Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5937333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:31:28+00:00 2026-05-22T15:31:28+00:00

I am importing approx 350,000 lines from a CSV file into MySQL using PHP

  • 0

I am importing approx 350,000 lines from a CSV file into MySQL using PHP (Symfony Framework if that matters) I am reading in each line and inserting into the SQL table as I go. This will be a daily process – and the number of lines will increase.

I have to translate 2 of the columns to a number (which is a foreign key). I want to know the most efficient way of doing it. I am experimenting with using a lookup table in MySQL and also an array in PHP – but I am wondering if there is a more efficient way.

There are approx 60 different combinations the 2 columns could be, here is an example of the translation table I have

Feature         Type          CODE
ANZIRL          Voice Call    8
BT2DT2          Data Call     6
BT2IL2          Voice Call    1
BT2UK2          Voice Call    2
DG2DG2          Voice Call    4
DG2DT2          Data Call     3
DG2EC           Voice Call    1
DG2EDQ          Voice Call    5
DG2EZY          Voice Call    7

And the CSV will be as follows

DG2DG2,x,x,x,Voice Call,x,x
DG2DT2,x,x,x,Data Call,x,x

etc…

I need to insert that into my table as

x,4,x,x
x,3,x,x

etc ….

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:31:28+00:00Added an answer on May 22, 2026 at 3:31 pm

    I would batch import the CSV file into MySQL as is (i.e. create a table that mirrors CSV field layout), and then run a query against the CSV import table to get the foreign key code.

    Something like:

    INSERT into sometable (code,other,fields)
    SELECT code, other, fields
    FROM codes c
    JOIN csvtable ct
    WHERE ct.feature = c.feature AND ct.type = c.type
    

    Basic idea is to not perform processing on row-by-row basis in PHP or MySQL, but to get all the data into MySQL and then run some version of above query to efficiently do the foreign key translation in 1-step.

    If you go row-by-row with 350,000+ records, that will be a fairly slow process, php is not terribly efficient…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm importing data from a CSV that contains approx 350 columns. This CSV import
I'm importing some data from a CSV file, and numbers that are larger than
While importing data from a flat file, I noticed that some of lines have
When importing numbers from a csv file, I need to convert them to floats
I am importing the CreateICeeFileGen() function from the unmanaged DLL mscorpe.dll in a C#
Which method makes the most sense for importing a module in python that is
After installing the VSTS Database GDR and importing a SQL Server 2005 database that
When I type 'from' (in a LINQ query) after importing System.Linq namespace , it
I have a table (table variable in-fact) that holds several thousand (50k approx) rows
I am using SSIS with SQL Server 2008 R2. I am importing large-ish text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.