受影响的行数Zend DB(UPDATE) [英] Number of affected rows Zend DB (UPDATE)

查看:134
本文介绍了受影响的行数Zend DB(UPDATE)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是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()计算行。



任何人都可以建议我如何改变这个$ c> rowCount



这是我连接到我的数据库的方式:

  $ parameters = array(
'host'=>'localhost',
'username'=>'root',
'password' =>'',
'dbname'=>'users'
);

try {
$ db = Zend_Db :: factory('Pdo_Mysql',$ parameters);
...

这是在我的 Bootstrap.php 。我这样做是因为我使用多个数据库。

解决方案

Zend_Db_Statement_Pdo有一个rowCount >

请参阅 API文档< a>


返回此语句对象执行的最后一个INSERT,DELETE或UPDATE语句的执行所影响的行数。 / p>

这意味着您可以: -

  $ rowsAffected = $ stmt-> rowCount(); 

在调用execute()后直接获取受影响的行数。


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.

解决方案

Zend_Db_Statement_Pdo has a rowCount() method.

See the API docs

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();

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆