Zend DB 受影响的行数(更新)

Number of affected rows Zend DB (UPDATE)(Zend DB 受影响的行数(更新))
本文介绍了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 受影响的行数(更新)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)