Solved

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

Posted on 2006-10-24
3
574 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
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

810 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