 |
|
จากโค้ด
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<?
//*** Get Document Path ***//
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
$OpenFile = "MyXls/MyExcelDB.xls";
//*** Create Exce.Application ***//
$xlApp = new COM("Excel.Application");
$xlBook = $xlApp->Workbooks->Open($strPath."/".$OpenFile);
//$xlBook = $xlApp->Workbooks->Open(realpath($OpenFile));
$xlSheet1 = $xlBook->Worksheets(1);
//*** Insert to MySQL Database ***//
$objConnect = mysql_connect("localhost","root","root") or die(mysql_error());
$objDB = mssql_select_db("mydatabase");
$i=2;
while($xlSheet1->Cells->Item($i,1) != "")
{
$strSQL = "";
$strSQL .= "INSERT INTO customer ";
$strSQL .= "(CustomerID,Name,Email,CountryCode,Budget,Used,Importtime) ";
$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)."', getdate()) ";
mssql_query($strSQL);
$i++;
}
//*** Close MySQL ***//
@mssql_close($objConnect);
//*** Close & Quit ***//
$xlApp->Application->Quit();
$xlApp = null;
$xlBook = null;
$xlSheet1 = null;
?>
Data Import/Inserted <?=$i;?> Record(s).
</body>
</html>
ตอน Import File น้อย เรคคอร์ดก็ไม่มีปัญหาครับ แต่พอเวลา Import หลายๆเรคอร์ด ประมาณ 800 กว่าเรคคอร์ด เริ่มมีปัญหาครับ
จะเกิด Error แบบนี้เพียบเลยครับ
Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near 'Times'. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: Query failed in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near 'Times'. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: Query failed in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near 't'. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near the keyword 'By'. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: message: The label 'Status' has already been declared. Label names must be unique within a query batch or stored procedure. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: message: The label 'Description' has already been declared. Label names must be unique within a query batch or stored procedure. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near 'Test'. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: message: The name "paper" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: message: The label 'Status' has already been declared. Label names must be unique within a query batch or stored procedure. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near 'Test'. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: message: The name "paper" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: message: Unclosed quotation mark after the character string ',getdate()) '. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: Query failed in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near 't'. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: message: The label 'Description' has already been declared. Label names must be unique within a query batch or stored procedure. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near the keyword 'and'. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: message: The label 'Status' has already been declared. Label names must be unique within a query batch or stored procedure. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: message: The label 'Description' has already been declared. Label names must be unique within a query batch or stored procedure. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near the keyword 'and'. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: message: The label 'Status' has already been declared. Label names must be unique within a query batch or stored procedure. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near the keyword 'and'. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: message: Unclosed quotation mark after the character string ',getdate()) '. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31
Warning: mssql_query() [function.mssql-query]: Query failed in C:\AppServ\www\importexcel\act_import.php on line 31
ต้องแก้อย่างไรบ้างครับ
Tag : PHP, Ms SQL Server 2005, Excel (Excel.Application)
|
|
 |
 |
 |
 |
Date :
2011-04-12 09:24:04 |
By :
paepatter |
View :
1367 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |