PHP + MySQL populating table with TXT fi

admin

Administrator
Staff member
Hi,

I need some help with the following script
The idea is to populate a table with dump
files. I磎 not sure about what am I doing. Any help is welcome.

Carlos
------------------------------------------

<?php

// clear cached values when use filesize()
clearstatcache();

// variables to connect to database
$host = "mysql.meudominio.com.br";
$user = "username";
$password = "password";
$dbname = "dbname";

// array with dump files names
$arqs_dump = array("APL.TXT","WBT.TXT");

// connects to database
$dbh = mysql_connect($host, $user, $password);
if (!$dbh) {
die("Can磘 connect!");
}
mysql_select_db($dbname);


// walks thru array
// reading dump files
// each dump file contains
// lines like
// INSERT INTO table VALUES("","","","","","","","","");

foreach($arqs_dump as $arqdump){

// opens dump file
$fp = @fopen("dumpdir/$arqdump","r") or
die("N鉶 consegui abrir o arquivo ".$grade);

// gets the size of dump file
$tam = filesize("dumpdir/$arqdump");

// reads dump file
$dump = @fread($fp,$tam);

// query database inserting
// dump file lines into table
$sth = mysql_query($dump, $dbh);

// closes dump file
@fclose($fp);

}

// closes connection to database
mysql_close($dbh);

echo "done";

?>
 
Back
Top