Solved

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

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

627 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