Solved

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

Posted on 2006-10-24
3
570 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 Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can i modify my File download link ? 6 49
How to use md5 hashing 3 29
Form Processing in PHP 11 32
mysqli 3 23
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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.

863 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

23 Experts available now in Live!

Get 1:1 Help Now