tony09uk
tony09uk

Reputation: 2991

Zend count affected rows

I am new to using the zend framework and and am really struggling. I am also as new to working with MVC.

I have created a simple CRUD application and am working on the update part. Updating the database is working fine but I would now like to add a facility that checks that an update was successful before outputting a success message to the user.

I have connected to the database with DbTable and hardcoded some information for testing

    public function updateRow()
    {  
    $update = new Application_Model_DbTable_Bins();

    $data = array(
        'BIN' => 'any',
        'DIVIDE' => 'two',
        'TYPE' => 'test',
        'STYLE' => 'none',
        'PRICE' => 'unknown',
        'STORAGE' => 'none',
        'BIN_ID' => 1
    );

    $where = $update->getAdapter()->quoteInto('BIN_ID = ?', 1);

    $update->update($data, $where);

}

My questions are:

How do I check if a row has been updated?

Should the above code be in the model as its is dealing with database?

Should I count the rows in the model or controller?

I am using zend version 1.12.

I have looked at the quickstart guide but it does not seem to mention this and I have looked at other zend documentation, but struggle to understand it.

Finally I use NetBeans so tend to rely on the pop up box which says which methods are available, which I know isn't perfect.

Upvotes: 0

Views: 295

Answers (1)

Joel Lord
Joel Lord

Reputation: 2173

The line:

$update->update($data, $where);

returns the number of rows affected. You can use:

$nbRows = $update->update($data, $where);

return $nbRows;

to return the number of affected rows by the update.

In NetBeans, the comments that you see in the popups are documentation from the Zend Framework itself. What you see in the popup is the comment that is placed just before the functions in the ZF source code. You should use that type of comments also when coding:

/**
* This function does something useful
* @params int $param1 An integer
* @return int The transformed integer
**/
public function usefulFunction($param1) {
  return $param1 + 1;
}

This way, you will see your comments in NetBeans when you are using your own functions.

With all this, my point was, the popups are usually pretty accurate with ZF in NetBeans. Just don't forget to check the return values of the functions that you use!

Upvotes: 2

Related Questions