|
 |
|
สอบถามหน่อยครับ เรื่อง Import .csv เข้าฐานข้อมูล รบกวนด้วยครับ |
|
 |
|
|
 |
 |
|
ใช้ navicat ครับ เลือกได้
|
 |
 |
 |
 |
Date :
2011-04-15 16:58:16 |
By :
avsqlz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าเป็นการ Import ผ่าน php อะครับ พอจะทำได้มั้ย
|
 |
 |
 |
 |
Date :
2011-04-16 21:20:40 |
By :
maxairzoom |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พอดีผมไปเจอ Code มา น่าจะเอามาประยุกต์ได้ แต่มันติด Error ว่า
Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft Office Excel<br/><b>Description:</b> Microsoft Office Excel ไม่สามารถเข้าถึงแฟ้ม 'C:\AppServ\www\1234\MyXls\MyCustomer.xls' มีสาเหตุที่เป็นไปได้หลายประการ ได้แก่ • ไม่มีชื่อแฟ้มหรือชื่อเส้นทางนั้น • แฟ้มนั้นถูกใช้โดยโปรแกรมประยุกต์อื่น • สมุดงานที่คุณกำลังพยายามบันทึกมีชื่อเดียวกับสมุดงานที่เปิดอยู่ในปัจจุบัน' in C:\AppServ\www\1234\phpImportExcelToDatabase.php:12 Stack trace: #0 C:\AppServ\www\1234\phpImportExcelToDatabase.php(12): variant->Open('C:\AppServ\www\...') #1 {main} thrown in C:\AppServ\www\1234\phpImportExcelToDatabase.php on line 12
ไปไม่เป็นเลยครับ ไม่เคยเจอ ยังไงรบกวนช่วยดูให้หน่อยนะครับ นั่งงมมาทั้งวันแล้ว
ตัว Code ครับ
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP(COM) Excel.Application Tutorial</title>
</head>
<body>
<?
//*** Get Document Path ***//
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
$OpenFile = "MyXls/MyCustomer.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","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
for($i=2;$i<=5;$i++){
If(trim($xlSheet1->Cells->Item($i,1)) != "")
{
$strSQL = "";
$strSQL .= "INSERT INTO customer2 ";
$strSQL .= "(CustomerID,Name,Email,CountryCode,Budget,Used) ";
$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)."') ";
mysql_query($strSQL);
}
}
//*** Close MySQL ***//
@mysql_close($objConnect);
//*** Close & Quit ***//
$xlApp->Application->Quit();
$xlApp = null;
$xlBook = null;
$xlSheet1 = null;
?>
Data Import/Inserted.
</body>
</html>
|
ประวัติการแก้ไข 2011-04-16 21:28:17 2011-04-16 21:29:00
 |
 |
 |
 |
Date :
2011-04-16 21:24:42 |
By :
maxairzoom |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เกี่ยวมั้ยครับ ถ้าผมใช้ Office 2007 มันเลย Error ไฟล์ผมก็ไม่ได้เปิดทิ้งไว้ มันก้ยัง Error งงครับ
|
 |
 |
 |
 |
Date :
2011-04-17 08:05:07 |
By :
maxairzoom |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จากตัวอย่างผมใช้ Office 2003 ครับ 
|
 |
 |
 |
 |
Date :
2011-04-17 08:38:43 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|