我正在使用 php 使用 ADO COM 更新 VFP 9.0 下的一些表。
在我指定任何Where子句之前,我可以选择和更新 DBF。
当我在查询中添加 where 子句时,它只是返回或更新 0 行。
$conn = new COM("ADODB.Connection");
$conn->Open('Provider=VFPOLEDB.1;Data Source="C:\\testDB.dbc";');
$query = "UPDATE TABLE1 set COL1 = \"AA\", COL2 = \"Updated value\" ";
$conn->Execute($query);
$query = "SELECT * FROM TABLE1 ";
$rs = $conn->Execute($query) or die("Error in query: $query. " . $conn->ErrorMsg());
while (!$rs->EOF) {
echo " Got COL1: " . $rs->Fields("COL1") . " :: COL2: " . $rs->Fields("COL2") . " id: " . $rs->Fields("ID") . "\n";
$rs->MoveNext();
}
结果:
Got COL1: AA :: COL2: Updated value id: 0
Got COL1: AA :: COL2: Updated value id: 1
Got COL1: AA :: COL2: Updated value id: 2
代码 2:使用 Where 子句
$query = "UPDATE TABLE1 set COL1 = \"BB\", COL2 = \"NEW2\" WHERE ID = 1";
$conn->Execute($query);
$query = "SELECT * FROM TABLE1 ";
$rs = $conn->Execute($query) or die("Error in query: $query. " . $conn->ErrorMsg());
while (!$rs->EOF) {
echo " Got COL1: " . $rs->Fields("COL1") . " :: COL2: " . $rs->Fields("COL2") . " id: " . $rs->Fields("ID") . "\n";
$rs->MoveNext();
}
结果:
Got COL1: AA :: COL2: Updated value id: 0
Got COL1: AA :: COL2: Updated value id: 1
Got COL1: AA :: COL2: Updated value id: 2
ID 列是上表中的键。
我对 VFP 比较陌生。我不确定这是 Visual Foxpro 设置还是其他阻止更新或选择是否有选择地进行的设置。