本文介绍了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 语句影响的行数.

这意味着您可以简单地:-

This means you can simply:-

$rowsAffected = $stmt->rowCount();

在调用 execute() 之后,您应该立即获得受影响的行数.

Straight after calling execute() and you should get the number of rows affected.

这篇关于Zend DB 受影响的行数(更新)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 09:07