I need a php script that can generate import text.txt to mysql database daily; the purpose is updating database refer to the logfile of tester machine at my production lines.
text.txt is the logfile tester machine, and line.txt is the temporary text file that used for update the latest line of text.txt that already upload to mysql.
The question is,
How to make a procedure at the next execution of the script will begin from the last line of line.txt. so it will not duplicate with the previous data imported.
and below is the script usage;
=============
PHP Code:
<? include("config.php"); //class untuk export file class exportFile { var $Query_ID=0; var $connection=0;
function connect() { if($this->connection==0) { $this->connection=mysql_connect(HOST,USERNAME,PASSWORD) or die("<b>Database Error</b><br>".mysql_error()); $SelectResult = mysql_select_db(DB, $this->connection) or die("Couldnot Select Database".mysql_error()); } else { echo "Connection Couldnot be Established"; die(); } }
// read the file into an array with each line being a seperate element // count the number of elements (lines) $fileName = "text.txt"; $fileArray = file( $fileName ); if( $fileArray ) { $numLines = count( $fileArray ); } // statement to compare line usage "text.txt" with temporary "line.txt" if ($numLines != $bytes) { $objFile->exportFileToDatbase("text.txt",",","r","sample",4,$numLines); // File name,Seprator,mode,tablename,field //save the latest line to "line.txt" $UO_Log = 'line.txt'; $UO_NewRecord .= "$numLines"; $UO_Handle = fopen($UO_Log, 'w'); fwrite($UO_Handle, $UO_NewRecord); fclose($UO_Handle); } else { echo "jumlah line ="; print $numLines ; echo " data is similar with the previous hours"; }