Solved

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

Posted on 2006-10-24
3
566 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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

744 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now