2016-04-21 33 views
-1

我想通过php更新我的传统访问系统中的记录,但在某些列上它不起作用。例如,下面的工作:PHP不允许某些列上的ACCESS更新

$query = "UPDATE Valuations SET SalesParticulars = '" . $salesparticulars . "', 
Company = '" . $company . "' WHERE Ref=" . $ref; 

如果我改变“公司”,以“名”这是行不通的,即使名称只是在数据库中的列完全一样的公司。

基本上我可以更新“公司”,而不是“名”,尽管它们都是相同的数据类型

我得到这个例外,我怎么能抓住它?

Fatal error: Uncaught exception 'com_exception' with message 'Source: Microsoft Access Database Engine
Description: Syntax error in UPDATE statement.' in

这是我的全部代码

// Create an instance of the ADO connection object 
$conn = new COM ("ADODB.Connection") or die("Cannot start ADO"); 

// Define the connection string and specify the database driver 
$connStr = "PROVIDER=Microsoft.Ace.OLEDB.12.0;Data Source=".realpath("HS_BE.accdb").";"; 

// Open the connection to the database 
$conn->open($connStr); 
$name= "gareth"; 
// Declare the SQL statement that will query the database 
$query = "UPDATE Valuations SET SalesParticulars = '" . $salesparticulars . "', 
Name = '" . $name . "' 
WHERE Ref=" . $ref; 

echo $query; 

// Execute the SQL statement and return records 
$rs = $conn->execute($query); 
+1

你尝试运行在MS Access直接相同的查询?它工作吗? – user4035

+0

@ user4035是的,它的确很奇怪 –

+0

有没有办法在执行查询后得到错误? – user4035

回答

2

这是因为名称是访问SQL保留字。

您可以在这样括号包起来:

$query = "UPDATE Valuations SET SalesParticulars = '" . $salesparticulars . "', 
[Name] = '" . $name . "' WHERE Ref=" . $ref; 
+0

这工作谢谢你 –