Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old January 22nd, 2003, 09:33 AM
jonathen jonathen is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Essex, UK
Posts: 44 jonathen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Non-CSVtextfile dump to mysql

Hi all,

Anyone know of any shareware or scripts out there that can take a textfile of addresses which has not got the column headings in it (non-csv, just entry after entry, and not in rows), and be able to dump all data to existing table by asking what line should dump to which column?

It would save me SO much time!

TIA

Reply With Quote
  #2  
Old January 23rd, 2003, 02:35 AM
DaemonJ DaemonJ is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Jamestown, TN USA
Posts: 61 DaemonJ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: Non-CSVtextfile dump to mysql

If I understand your post correctly, the file looks like:

Joe User
Some company
123 Main Street
Apt 2A
Somewhere
CA
90210

or something like that?

If that is the case, are there always the same number of lines for each address with blank lines in place for missing data?

If so, you should be able to write such a script in a short time.

Reply With Quote
  #3  
Old January 27th, 2003, 10:51 AM
jonathen jonathen is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Essex, UK
Posts: 44 jonathen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: Non-CSVtextfile dump to mysql

Hi,

Thanks for the reply - sorry for the delay in replying, been so busy. Yes, that's it exactly; every entry has the same number of lines. So...do you have any idea of what syntax I'd need for such a script?

TIA

Reply With Quote
  #4  
Old January 27th, 2003, 12:34 PM
xs0 xs0 is offline
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Ljubljana, Slovenia
Posts: 760 xs0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: Non-CSVtextfile dump to mysql

Something like what follows should work. Note that you'll have to modify it to fit your data and database. I'll also assume that the data is in the exact format posted above.
php Code:
Original - php Code
  1.  
  2. <?php
  3.  
  4. // first, connect to database
  5. mysql_connect("localhost", "username", "password");
  6. mysql_select_db("mydatabase");
  7.  
  8. // then, open the file
  9. $infile=fopen("myfile.txt", "r");
  10.  
  11. // and then, until we reach the end of file, read the data
  12. while (!feof($infile)) {
  13.     $name=addslashes(trim(fgets($infile, 1000)));
  14.     $company=addslashes(trim(fgets($infile, 1000)));
  15.     $address1=addslashes(trim(fgets($infile, 1000)));
  16.     $address2=addslashes(trim(fgets($infile, 1000)));
  17.     $city=addslashes(trim(fgets($infile, 1000)));
  18.     $state=addslashes(trim(fgets($infile, 1000)));
  19.     $zipcode=addslashes(trim(fgets($infile, 1000)));
  20.    
  21.     // finally, insert the data into database
  22.     mysql_query("INSERT INTO mytable(name,company,address1,address2,city,state,  zipcode) VALUES ('$name', '$company', '$address1', '$address2', '$city', '$state', '$zipcode')");
  23. }
  24. ?>


To match with your data/table, modify the number of lines read for each entry and the order and names of fields in the table in your database inside the mysql_query statement. If you're not using MySQL, you'll also need to change the database calls, but the principle stays the same...

Hope this helped.

Reply With Quote
  #5  
Old January 27th, 2003, 02:32 PM
jonathen jonathen is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Essex, UK
Posts: 44 jonathen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: Non-CSVtextfile dump to mysql

Thank you for that, it is greatly appreciated

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Non-CSVtextfile dump to mysql


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 11 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek