DrDankWD Posted November 30, 2006 Share Posted November 30, 2006 I am trying to insert a large (1.5gb) tab delimited file into a database. I found this script but cannot seem to get it to function correctly, it is only inserting the id field and leaving the rest blank.[code]<? $link = mysql_connect($server,$dbuser,$password) or die("Could not connect"); $db = mysql_select_db($database, $link) or die("Could not select database"); $linenumber=1; $count=1; $startcount=$_REQUEST['start']; if (!isset($startcount)) { $startcount=1; } //Open file and read line by line..... $handle = fopen($filename, "r"); while (!feof($handle)) { //print "<br>".$linenumber; //Use this if the data is a SQL export... $sqlquery = fgets($handle); //If the data is | delimeted... list($id, $first_name, $last_name, $bus_name, $blank, $add_2, $add_1, $city, $state, $zip, $zip_2, $carrier_code, $employees, $phone, $db_sic) = explode("/t",$sqlquery); $sqlquery="INSERT INTO data VALUES ('$id','$first_name','$last_name','$bus_name','$blank','$add_2','$add_1','$city','$state','$zip','$zip_2','$carrier_code','$employees','$phone','$db_sic')"; if ($linenumber>=$startcount){ $result = mysql_query($sqlquery); print "<br>".$count.":".$linenumber."- ".$startcount; usleep($timedelay); $count++; if ($count>$recordstoinsert){ break; } if(mysql_error()) { echo mysql_error() ."<br>\n"; } } $linenumber++; } $nextrecord=$startcount + $count-1; $recordsinserted=$count-1; print "<br>Records inserted=".$recordsinserted; print "<br>Next Record=".$nextrecord; if($recordsinserted<$recordstoinsert){ print "<br>Done!"; exit; }?>[/code] Link to comment https://forums.phpfreaks.com/topic/29034-inserting-large-tab-delimited/ Share on other sites More sharing options...
DrDankWD Posted November 30, 2006 Author Share Posted November 30, 2006 Nevermind, I have a /t instead of \t. Sorry for the wasted post!-DrDank Link to comment https://forums.phpfreaks.com/topic/29034-inserting-large-tab-delimited/#findComment-133032 Share on other sites More sharing options...
DrDankWD Posted December 1, 2006 Author Share Posted December 1, 2006 Okay so I found my silly error and got the script working correctly. I was letting it run on my 1.5 gb file over night and I think the server was rebooted because I lost mysql connection and the script stopped. So now I need to figure otu a way to make the script not start at the top of the file but from a specific line, anyone have any ideas?Thanks! Link to comment https://forums.phpfreaks.com/topic/29034-inserting-large-tab-delimited/#findComment-133499 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.