PHP不允许在某些列上进行ACCESS更新

时间:2016-04-21 08:32:52

标签: php ms-access

我正在尝试通过php更新我的旧版访问系统中的记录,但在某些列上它不起作用。例如,以下作品:

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

如果我改变"公司"到"姓名"即使名称只是数据库中的一列与公司完全相同,它也不起作用。

基本上我可以更新"公司"但不是"名称",即使它们都是相同的数据类型

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

  

致命错误:未捕获的异常' com_exception'消息' 来源: Microsoft Access数据库引擎
描述: UPDATE语句中的语法错误。'在

这是我的完整代码

// 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 个答案:

答案 0 :(得分:2)

那是因为 Name 是Access SQL中的保留字。

你可以把它包在这样的括号中:

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