Solved

Script/Class/Function to import fixed width unicode into mySQL

Posted on 2006-10-24
3
579 Views
Last Modified: 2013-12-12
As the subject says I am looking for some type of class/function/script that handles importing a text file that is a fixed field length unicode file into a mySQL database.

Something easy to use and flexible is even better.  Simple and working is the best.

I know this type of stuff has had to be done before.
0
Comment
Question by:blainehilton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 49

Accepted Solution

by:
Roonaan earned 500 total points
ID: 17876083
In it most simple form it would be something like this:

$handle = fopen('unicodefile.txt', 'r');

while($line = fgets($handle, 4096)) {
  $field1 = trim(substr($line, 0, 10));
  $field2 = trim(substr($line, 10, 20));
  $field3 = trim(substr($line, 20, 30));
  $field4 = trim(substr($line, 30, 40));

  mysql_query('INSERT INTO TABLE (f1,f2,f3,f4) values("'.mysql_real_escape_string($field1).'","'.mysql_real_escape_string($field2).'","'.mysql_real_escape_string($field3).'","'.mysql_real_escape_string($field4).'")');
}

-r-
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question