$query="LOAD DATA LOCAL INFILE 'ARTIKEL8.TXT' REPLACE INTO TABLE product FIELDS TERMINATED BY ';' ENCLOSED BY '\"' IGNORE 1 LINES (`Id`,`f1`,`f2`,`f3`,`f4`,`f5`,`f6`,`f7`,`f8`)";
mysql_query($query) or die ("query error");
Tag : - - - -
Date :
27 ก.พ. 2551 12:44:32
By :
อ้อย
View :
1638
Reply :
1
No. 1
Guest
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & Text To MySQL</title>
</head>
<body>
<?
copy($_FILES["fileCSV"]["tmp_name"],$_FILES["fileCSV"]["name"]); // Copy/Upload CSV
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database"); // Conect to MySQL
$objDB = mysql_select_db("mydatabase");
$strFileName = "thaicreate.txt";
$objFopen = fopen($strFileName, 'r');
if ($objFopen) {
while (!feof($objFopen)) {
$file = fgets($objFopen, 4096);
$strSQL = "INSERT INTO customer ";
$strSQL .="(Name) ";
$strSQL .="VALUES ";
$strSQL .="('".$file."') ";
$objQuery = mysql_query($strSQL);
}
fclose($objFopen);
}
echo "Import Done.";
?>
</table>
</body>
</html>