简体   繁体   English

PHP - 在 ADODB 中获取受影响的行

[英]PHP - Get affected rows in ADODB

I using ADODB to create a connection to my database.我使用 ADODB 创建到我的数据库的连接。 I update the data in my database, there is no error.我更新了数据库中的数据,没有错误。 The problem is that I can't get the number of affected rows by Affected_Rows() .问题是我无法通过Affected_Rows()获得受影响的行数。 I tried with very simple code but it is not working.我尝试使用非常简单的代码,但它不起作用。 Here is my code:这是我的代码:

$sql = "UPDATE User SET Name=N'MyName' WHERE Id=1";
$conn = new COM ("ADODB.Connection") or die("Cannot start ADO");
$cs = "provider=sqloledb;"."server=localhost;database=Test;uid=Admin;pwd=123456;Max Pool Size=100";
$conn->open($cs);

//there is no error in connecting process. I can add, update, delete normally.
if($conn->Execute($sql) === false)
{
    trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->ErrorMsg(), E_USER_ERROR);
}
else 
{
    echo $conn->Affected_Rows();  //<-- Error in here
}

I have read about this function inhere .我在此处阅读了有关此功能的信息 My code above is almost same with example here .我上面的代码与这里的示例几乎相同。 Is there any other way to get the number of affected rows in ADODB-PHP?有没有其他方法可以获取 ADODB-PHP 中受影响的行数?

About Affected_Rows() , I don't know why it isn't working.关于Affected_Rows() ,我不知道为什么它不起作用。 There is another very simple way to get the number of affected rows after execute query.还有另一种非常简单的方法可以在执行查询后获取受影响的行数。

$conn->Execute($sql,$affected_rows);

echo $affected_rows;

$affected_rows return from Execute function will have value equal to number of affected rows of that query. $affected_rows从 Execute 函数返回的值将等于该查询的受影响行数。

just for mark.只是为了标记。

your code:你的代码:

echo $conn->Affected_Rows()

is ADODB SDK methods: http://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:affected_rows是 ADODB SDK 方法: http : //adodb.org/dokuwiki/doku.php? id=v5:reference:connection: affected_rows

NOT a native COM("ADODB.connection") method.不是本机 COM("ADODB.connection") 方法。

but i have same problem because this method return "variant Object" so i can't get the value.但我有同样的问题,因为此方法返回“变体对象”,所以我无法获得该值。

i fixed this by edit SDK source file : adodb5/drivers/adodb-ado5.inc.php #44 line:我通过编辑 SDK 源文件修复了这个问题:adodb5/drivers/adodb-ado5.inc.php #44 行:

$this->_affectedRows =new VARIANT;

to:到:

$this->_affectedRows = null;

then Affected_Rows() method can return a real number for me.那么 Affected_Rows() 方法可以为我返回一个实数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM