使用 php 更新 Visual FoxPro DBF

发布于 2024-09-04 11:31:42 字数 1640 浏览 7 评论 0原文

我正在使用 php 使用 ADO COM 更新 VFP 9.0 下的一些表。

我可以选择并更新 DBF,直到指定任何 Where 子句。
当我向查询添加 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:WithWhere子句

$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 设置或其他阻止更新的设置或选择是否有选择地完成。

I am using php to update some tables under VFP 9.0 using ADO COM.

I am able to select and update the DBF until i specify any Where clause.
The moment i add a where clause to the query, it simply returns or updates 0 rows.

$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();
}

Result:

 Got COL1: AA :: COL2: Updated value                  id: 0
 Got COL1: AA :: COL2: Updated value                  id: 1
 Got COL1: AA :: COL2: Updated value                  id: 2

Code 2: With Where clause

$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();
}

Result:

 Got COL1: AA :: COL2: Updated value                  id: 0
 Got COL1: AA :: COL2: Updated value                  id: 1
 Got COL1: AA :: COL2: Updated value                  id: 2

The ID column is the key in the above table.

I am relatively new to VFP. I am not sure if this a Visual Foxpro setting or something else which prevents the updates or select if done selectively.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生寂 2024-09-11 11:31:42

您使用的标准 SQL 样式语句很容易与 VFP 兼容。尽管您的示例很简单,但我会先尝试稍作修改。不要使用转义“,只需在示例中使用单引号,例如

UPDATE TABLE1 set COL1 = 'AA', COL2 = 'Updated value' where ID = 1

看看这是否有任何作用。一旦起作用,我就会去参数化查询以确保安全......特别是当基于 Web 的 VFP 不能像其他数据库那样使用“命名占位符”时,但使用“?”来使用基于序数的占位符。应该在哪里应用您的“值”...例如

UPDATE TABLE1 set col1 = ?, col2 = ? where id = ?

然后,在添加参数时,根据与占位符相同的顺序添加

YourAdo.Parameters.Add( "ForColumn1", variableForColumn1 );
YourAdo.Parameters.Add( "ForColumn2", variableForColumn2 );
YourAdo.Parameters.Add( "IDKeyColumn", variableForID );

然后,您应该很

抱歉,我无法专门帮助您了解 PHP,因为这不是我直接熟悉的,但应该可以帮助指导您。

The standard SQL-style statements you are using are easily compatible with VFP. As simple as your sample is, I would try one slight alteration first. Instead of using escape ", just use single quotes around your sample such as

UPDATE TABLE1 set COL1 = 'AA', COL2 = 'Updated value' where ID = 1

See if that does anything. Once that is working, I would then go to parameterized queries for safety... especially when web-based. VFP doesn't work with "named place-holders" like some other databased, but ordinal based place-holders by using a '?' where your "value" should be applied... such as

UPDATE TABLE1 set col1 = ?, col2 = ? where id = ?

Then, when adding the parameters, add based on the same sequence as the ? place-holders

YourAdo.Parameters.Add( "ForColumn1", variableForColumn1 );
YourAdo.Parameters.Add( "ForColumn2", variableForColumn2 );
YourAdo.Parameters.Add( "IDKeyColumn", variableForID );

Then, you should be good to go.

Sorry I can't help specifically with PHP as thats not one I'm directly familiar with, but should help guide you on it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文