Zend DB 受影响的行数(更新)
我是 Zend Framework 的新手,我想知道如何从中获取受影响的行数:
$sql = "UPDATE auth SET act='', status='1' WHERE username = ? AND act = ? ";
$stmt = $this->dbh->prepare($sql);
$stmt->execute(array($this->username, $this->key));
我在这个论坛上看到了一些帖子,但它们基于 MySQLi 和 SELECT 语句,您可以在其中实际计算使用 count()
的行。
任何人都可以建议我如何更改它以支持 rowCount
。
这就是我连接到数据库的方式:
$parameters = array(
'host' => 'localhost',
'username' => 'root',
'password' => '',
'dbname' => 'users'
);
try {
$db = Zend_Db::factory('Pdo_Mysql', $parameters);
...
它位于我的 Bootstrap.php
中。我这样做是因为我使用多个数据库。
I'm new to Zend Framework and I'd like to know how I can get the number of affected rows from this:
$sql = "UPDATE auth SET act='', status='1' WHERE username = ? AND act = ? ";
$stmt = $this->dbh->prepare($sql);
$stmt->execute(array($this->username, $this->key));
I saw a few posts on this forum, but they we based on MySQLi and SELECT statements where you can actually count the rows using count()
.
Can anyone suggest how I can alter this to support rowCount
.
This is how I connect to my database:
$parameters = array(
'host' => 'localhost',
'username' => 'root',
'password' => '',
'dbname' => 'users'
);
try {
$db = Zend_Db::factory('Pdo_Mysql', $parameters);
...
This is in my Bootstrap.php
. I did it this way because I work with more than one databases.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Zend_Db_Statement_Pdo 有一个 rowCount() 方法。
请参阅 API 文档
这意味着您可以简单地: -
在调用execute()之后,您应该立即获得受影响的行数。
Zend_Db_Statement_Pdo has a rowCount() method.
See the API docs
This means you can simply:-
Straight after calling execute() and you should get the number of rows affected.