English 中文(简体)
更新在 zend 框架中的 LIMIT 更新 [重复]
原标题:Update with a LIMIT in zend framework [duplicate]
This question already has answers here:
Closed 11 years ago.

Possible Duplicate:
How do I add a limit to update-query in Zend Framework?

I would like to do a update and place LIMIT 1 as precaution. Here is my code:

$vals = array();
$vals[ status ] =  closed ;
$where = $write->quoteInto( id =? , $orderID);

$write->update("order", $vals ,$where);

这条查询中,我在哪里可以添加一个限制使用权?

(看起来像过去有人问过 但我希望有人有答案)

最佳回答

It looks like you re using Zend_Db_Adapter to perform your queries so I m not sure you can do what I do, anyway here goes.
I usually use the Zend_Db_Table_Row save() method to insert and update records, however I also use the DbTable models to provide access to the Table and Table_Row abstract api s.

public function save(Music_Model_Artist $artist) {
        //if id is not null
        if (!is_null($artist->id)) {
            //find row, uses fetchRow() so will return NULL if not found
            $row = $this->findById($artist->id);
            $row->id = $artist->id;
        } else {
            //if ID is null create new row
            $row = $this->_getGateway()->createRow();
        }
        //assign data to row
        $row->name = $artist->name;
        //save new row or update
        $row->save();
        //return the row, in case I need it for something else
        return $row;
    }

这意味着,如果我在数据阵列(或在此情况下实体对象)中包含和标识该行,则该行将更新,如果对象中没有标识,则将创建新行。

如果你好奇我是如何 建造这堂课的:

public function __construct(Zend_Db_Table_Abstract $tableGateway = NULL) {
        //pass in concrete DbTable Model, parent alts to using table name string to construct class
        $this->_tableGateway = new Application_Model_DbTable_Artist();
        parent::__construct($tableGateway);
    }

希望这能帮上点忙

问题回答

嗯... 我的Zend生锈了, 但我想在过去我曾经使用过: 使用 http://framework.zend.com/manual/en/zend.db.statement.html 执行 SQL(选择/插入/更新)作为正常的 sql 语句...

是的,但所有旧的和当前的信息是正确的 - 更新 () 没有设置限制的能力 - 您只需要希望您正确设计 DB 并且这些表格不会有重复的密钥!

还有... 秩序是一个非常糟糕的表名: ) 命令是 MySQL (事实上任何 DB! ) 的保留词 。

Ok, 似乎没有办法做到这一点, 我只是决定使用 weragt 查询功能。 我仍然使用所建的功能, 将任何有趣的不想要的值从位置删除 。

$where = $write->quoteInto( id =? , $order_id);
$write->query("UPDATE orders SET status =  closed  WHERE $where LIMIT 1");




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签