Number of affected rows Zend DB (UPDATE)(Zend DB 受影响的行数(更新))
问题描述
我是 Zend Framework 的新手,我想知道如何从中获取受影响的行数:
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));
我在这个论坛上看到了一些帖子,但它们基于 MySQLi 和 SELECT 语句,您可以使用 count()
实际计算行数.
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()
.
谁能建议我如何更改它以支持 rowCount
.
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);
...
这是在我的 Bootstrap.php
中.我这样做是因为我使用了多个数据库.
This is in my Bootstrap.php
. I did it this way because I work with more than one databases.
推荐答案
Zend_Db_Statement_Pdo 有一个 rowCount() 方法.
Zend_Db_Statement_Pdo has a rowCount() method.
请参阅 API 文档
返回受此语句对象执行的最后一条 INSERT、DELETE 或 UPDATE 语句影响的行数.
Returns the number of rows affected by the execution of the last INSERT, DELETE, or UPDATE statement executed by this statement object.
这意味着您可以简单地:-
This means you can simply:-
$rowsAffected = $stmt->rowCount();
在调用 execute() 之后,您应该立即获得受影响的行数.
Straight after calling execute() and you should get the number of rows affected.
这篇关于Zend DB 受影响的行数(更新)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Zend DB 受影响的行数(更新)


基础教程推荐
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01