Jump to content


Photo

parsing a large file and inserting content into MySQL


  • Please log in to reply
3 replies to this topic

#1 obyno

obyno
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 21 September 2006 - 12:53 PM

I am trying to read the contents of a forty megabyte text file that was saved as a Tab delimited file from MS Excel. The intention is to insert the columns within into a MySQL table. The trouble is that the maximum times in minutes which a file can be executed before php gives up is not long enough to compare with the lenth of time thi is taking. Can somebody please suggest to me how I might accomplish this? Thanks in advance

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 21 September 2006 - 12:54 PM

increase your time out in the php.ini.

good luck.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 obyno

obyno
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 21 September 2006 - 01:11 PM

I am hosted on a public server where I have no access to the php.ini. I dont think the Administrators would take kindly to any such requests from me. Thanks though.

#4 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 21 September 2006 - 01:54 PM

Have a look at LOAD DATA INFILE


Simple example...

<?

	define ( 'DB_HOST', 'localhost:3306' );     // should not need to change
	define ( 'DB_USER', 'user' );               // enter the user name for this database
	define ( 'DB_PASS', 'pass' );               // enter the password for this database
	define ( 'DB_NAME', 'my_db' );              // enter the database name you are connecting to


	define ( 'DB_TABLE', 'my_table' );          // enter the NAME of the database TABLE to INSERT data into
	define ( 'DBF_CSVP', './path_to/csv.txt' ); // enter the PATH and NAME of the CSV FILE to IMPORT

	mysql_connect ( DB_HOST, DB_USER, DB_PASS ) or die ( 'Connection Error: ' . mysql_error () );
	mysql_select_db ( DB_NAME ) or die ( 'Select DB (' . DB_NAME . ') Error: ' . mysql_error () );
	mysql_query ( "LOAD DATA INFILE '" . DBF_CSVP . "' INTO TABLE " . DB_TABLE . " FIELDS TERMINATED BY '\\t\\t' OPTIONALLY ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\\r\\n'" );

?>


me




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users