Jump to content

Problem with LOAD DATA INFILE query


RyanMinor

Recommended Posts

I am having a strange issue with running a LOAD DATA INFILE query from a PHP script. Here is my PHP code:

$query = $db->prepare("LOAD DATA INFILE ? 
    INTO TABLE csv_data 
    FIELDS TERMINATED BY ',' 
    LINES TERMINATED BY '\r\n' 
    (game_week, home_team, home_score, visitor_team, visitor_score)");
if (!$query->execute(array($location))) {
    $errors[] = 'CSV upload query failed.';
} else {

 

The first five lines of the csv file are as follows:

1,Abington,24,Fels,8
1,Abington Heights,28,Pittston Area,0
1,Academy Park,29,Marple Newton,20
1,Aliquippa,36,Ambridge,0
1,Allegany MD,56,Southern Garrett MD,6

 

When I run this query everything gets uploaded perfect except that the first value in the database table for game_week is 0 instead of 1. So the first row looks like this:

game_week | home_team | home_score | visitor_team | visitor_score
0 | Abington | 24 | Fels | 8

 

Why is that first value 0 instead of 1. I really don't understand why this is happening. Any help is greatly appreciated.

 

Also, here is my table structure and I am using XAMPP on Windows 7 if that matters at all:

CREATE TABLE csv_data ( 
    game_id int(4) NOT NULL AUTO_INCREMENT, 
    game_date date NOT NULL, 
    game_week tinyint(2) NOT NULL, 
    home_team varchar(250) NOT NULL, 
    home_score tinyint(3) NOT NULL, 
    visitor_team varchar(250) NOT NULL, 
    visitor_score tinyint(3) NOT NULL, 
    PRIMARY KEY (game_id)
) 
ENGINE=MyISAM 
AUTO_INCREMENT=675 
DEFAULT CHARSET=latin1

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.