#1  
Old 13th September 2008, 05:11
qwe010 qwe010 is offline
Member
 
Join Date: Nov 2006
Posts: 52
Thanks: 0
Thanked 1 Time in 1 Post
Default can i do that in php

hello

i have

text file names.txt

inside it

many lines ( names )

can i creat php code to

read the file and put all the names in database ?
Reply With Quote
Sponsored Links
  #2  
Old 13th September 2008, 11:14
till till is online now
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 34,595
Thanks: 792
Thanked 4,984 Times in 3,904 Posts
Default

Thats relatively easy:

Code:
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
mysql_select_db('mydb', $link);
$lines = file("/path/to/your.txt");
foreach($lines as $line) {
  $name = trim($line);
  mysql_query("INSERT INTO mytable (myname) VALUES ('$name')",$link);
}
mysql_close($link);
__________________
Till Brehm
--
Get ISPConfig support and the ISPConfig 3 manual from ispconfig.org.
Reply With Quote
  #3  
Old 13th September 2008, 23:25
qwe010 qwe010 is offline
Member
 
Join Date: Nov 2006
Posts: 52
Thanks: 0
Thanked 1 Time in 1 Post
Default

thank you very much

but if the file to big

how can i make the insert in the database on parts

and how i know if the process done without error
Reply With Quote
  #4  
Old 14th September 2008, 13:18
till till is online now
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 34,595
Thanks: 792
Thanked 4,984 Times in 3,904 Posts
Default

How big? If its not larger then say 100 or 100 MB, this should work. You will just have to set the memory limit in PHP to a higher value.

Otherwise youz will have to take a look in the PHP documentation, you will find there als file functions to read a file line by line.
__________________
Till Brehm
--
Get ISPConfig support and the ISPConfig 3 manual from ispconfig.org.
Reply With Quote
  #5  
Old 15th September 2008, 01:28
qwe010 qwe010 is offline
Member
 
Join Date: Nov 2006
Posts: 52
Thanks: 0
Thanked 1 Time in 1 Post
Default

just 2 gb

Quote:
take a look in the PHP documentation
i did but i don't find any thing

but i searched in google and i found that
PHP Code:
$file "file.txt";
$fh fopen($file"rb");

//feof = end of file
while(!feof($fh)) {
  
$line fgets($fh); //fgets reads one line at a time

  //do something


PHP Code:
$read_lim 8192//size in bytes to load into memory
$file "test.txt";
$fh fopen($file"rb");
$size filesize($file); //total file size

while ($size 0) {
  
$rlen = ($size $read_lim) ? $read_lim $size//read length
  
$buffer fread($fh$rlen);

  
//do something

  
$size -= $rlen;


what the best ?
Reply With Quote
  #6  
Old 16th September 2008, 23:01
qwe010 qwe010 is offline
Member
 
Join Date: Nov 2006
Posts: 52
Thanks: 0
Thanked 1 Time in 1 Post
Default

up any help please
Reply With Quote
  #7  
Old 5th October 2008, 17:44
qwe010 qwe010 is offline
Member
 
Join Date: Nov 2006
Posts: 52
Thanks: 0
Thanked 1 Time in 1 Post
 
Default

up any help please
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ffmpeg Video support for ubuntu 7.10 [suphp-ispconfig] amaurib Installation/Configuration 13 16th February 2010 17:26
Freebsd 6.1 support misterm Installation/Configuration 10 9th April 2009 09:29
ispconfig php 5 errors itamarjp Installation/Configuration 8 25th April 2008 10:20
network issues now it says "401 The web site is blocked by administrator" Check General 3 26th February 2008 14:22
Apache2 Freezes celtic Server Operation 31 28th May 2007 17:18


All times are GMT +2. The time now is 17:18.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.