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 9090147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:18:33+00:00 2026-06-16T22:18:33+00:00

Possible Duplicate: Import CSV file directly into MySQL Export CSV from Mysql I want

  • 0

Possible Duplicate:
Import CSV file directly into MySQL
Export CSV from Mysql

I want to read from a CSV file that I have on the system (C:/xampp/htdocs/live/quotes.csv)
into my MySQL table.

I created the table like this:

mysql_query("CREATE TABLE IF NOT EXISTS datas(
                                 id int(255) NOT NULL auto_increment,
                                 symbol_t char(6) NOT NULL,
                                 last_trade_price_only_t varchar(100) NOT NULL,
                                 a varchar(30) NOT NULL,
                                 b varchar(30) NOT NULL,
                                 c varchar(30) NOT NULL,
                                 d varchar(30) NOT NULL,
                                 e varchar(30) NOT NULL,
                                 PRIMARY KEY (id) 
)");

and now want to write the CSV in the table like that:

$location="C:/xampp/htdocs/live/quotes.csv";
$sql = "LOAD DATA LOCAL INFILE '{$location}'
        INTO TABLE '{datas}'
        FIELDS TERMINATED BY ','
        OPTIONALLY ENCLOSED BY '\"'
        LINES TERMINATED BY '\n'
        ('symbol_t', 'last_trade_price_only_t','a','b','c','d','e')";

mysql_query($sql);

but somehow it is not working. Did I set the location wrong?

And i got another question. If i want to get an external csv (yahoo finanace csv) with the url: http://finance.yahoo.com/d/quotes.csv?s=$ticker_url&f=sl1=.csv
($ticker_url is a collection of ticker symbols). Does my $location var have to the just the url, or do I have to open it first with fopen(url)?

now:

$data_tablename="data_".date("m_d_Y",time());
$filename="C:\\xampp\\htdocs\\live\\quotes.csv";
$sql = "LOAD DATA LOCAL INFILE '{$filename}'
        INTO TABLE '{$data_tablename}'
        FIELDS TERMINATED BY ','
        OPTIONALLY ENCLOSED BY '\"'
        LINES TERMINATED BY '\r\n'
        ('symbol_t', 'last_trade_price_only_t','a','b','c','d','e')";

Table

  • 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-06-16T22:18:35+00:00Added an answer on June 16, 2026 at 10:18 pm

    Since you are using Windows your lines in your CSV file are likely terminated with \r\n so you need to change:

    LINES TERMINATED BY '\n'
    

    To

    LINES TERMINATED BY '\r\n'
    

    Per the documentation:

    If you have generated the text file on a Windows system, you might
    have to use LINES TERMINATED BY ‘\r\n’ to read the file properly,
    because Windows programs typically use two characters as a line
    terminator. Some programs, such as WordPad, might use \r as a line
    terminator when writing files. To read such files, use LINES
    TERMINATED BY ‘\r’.

    Also:

    '{datas}'
    

    Probably was meant to be:

    '{$datas}'
    

    Also:

    ('symbol_t', 'last_trade_price_only_t','a','b','c','d','e')";
    

    Needs to be:

    (`symbol_t`, `last_trade_price_only_t`, `a`, `b`, `c`, `d`, `e`)";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some CSV data files that I want to import into mySQL. I
Possible Duplicate: How do I read this text file and Insert into MySQL? I
Possible Duplicate: Best practice: Import mySQL file in PHP; split queries How to import
Possible Duplicate: Creating a dictionary from a CSV file I am having an issue
Possible Duplicate: How to import contact from gmail using java I want to import
Possible Duplicate: Python package structure Hello, I'm looking to import a python file that
Possible Duplicate: Import / read / load variables from matlab matfile it C# I
Possible Duplicate: How to import LARGE sql files into mysql table Using php i
Possible Duplicate: Difference between @import and link in CSS I have a .css file
Possible Duplicate: Importing Python modules from different working directory I want to import a

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.