|
|
|
สอบถามเรื่อง code Import Excel ---> Mysql หน่อยค่ะ |
|
|
|
|
|
|
|
Import Excel ---> Mysql
ข้อมูลที่เป็นไทยเวลาที่ Import Excel ---> Mysq
ไม่เป็นไทยต้องกำหนดตรงไหนค่ะ
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP(COM) Excel.Application Tutorial</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?
//*** Get Document Path ***//
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
$OpenFile = "MyXls/2010.xls";
//*** Create Exce.Application ***//
$xlApp = new COM("Excel.Application");
$xlBook = $xlApp->Workbooks->Open($strPath."/".$OpenFile);
$xlSheet1 = $xlBook->Worksheets(1);
//*** Insert to MySQL Database ***//
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("data");
//$objDB = mysql_db_query("data","SET NAMES UTF8"); //*ลองแบบนี้แล้วได้ค่ะ
for($i=2;$i<=3;$i++){
If(trim($xlSheet1->Cells->Item($i,1)) != "")
{
$strSQL = "";
$strSQL .= "INSERT INTO test";
$strSQL .= "(stu_id,front,fname,lname,address,tel,fa_name, mo_name,birthday,type_id,major_id,blod,nat,bud,stname,staddress,sttel,Thumbnails,FilesName)";
$strSQL .= "VALUES ";
$strSQL .= "('".$xlSheet1->Cells->Item($i,1)."','".$xlSheet1->Cells->Item($i,2)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,3)."','".$xlSheet1->Cells->Item($i,4)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,5)."','".$xlSheet1->Cells->Item($i,6)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,7)."','".$xlSheet1->Cells->Item($i,8)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,9)."','".$xlSheet1->Cells->Item($i,10)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,11)."','".$xlSheet1->Cells->Item($i,12)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,13)."','".$xlSheet1->Cells->Item($i,14)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,15)."','".$xlSheet1->Cells->Item($i,16)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,17)."','".$xlSheet1->Cells->Item($i,18)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,19)."') ";
mysql_query($strSQL);
}
}
//*** Close MySQL ***//
@mysql_close($objConnect);
//*** Close & Quit ***//
$xlApp->Application->Quit();
$xlApp = null;
$xlBook = null;
$xlSheet1 = null;
?>
Data Import/Inserted.
</body>
</html>
Tag : - - - -
|
|
|
|
|
|
Date :
2010-01-13 01:40:49 |
By :
kwanla |
View :
1105 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
บรรทัดที่ 20 ไง ก็เห็นทำแล้วนิครับ
|
|
|
|
|
Date :
2010-01-13 07:53:31 |
By :
panyapol |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|