Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-19-2007, 11:26 PM
Junior Member
 
Join Date: May 2007
Posts: 9
Default How do I Update a Row in my Database? [NOT SOLVED YET]

Hello all,

I've been using the Zend framework for a while now, but I've run into a problem with the Zend_Db class:

When trying to use the code in the documentation here Zend Framework: Documentation (Example 10.105. Example of changing a column in a row) I'm finding that PHP throws an exception saying, "Notice: Trying to get property of non-object" - this refers to this line in the example, "$row->bug_status = 'FIXED';". So it seems that either I've missed something simple, or the Zend framework has changed and the documentation hasn't been updated.

Any help would be muchly appreciated!

Regards,

Socceroos.

Last edited by socceroos : 11-22-2007 at 09:49 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 11-19-2007, 11:40 PM
Junior Member
 
Join Date: May 2007
Posts: 9
Default

Here is the code that I use:

Code:
                $where = "SELECT * FROM table WHERE ".$this->DB->quoteInto('user = ? ', $this->user['id']);
                $where .= " AND ".$this->DB->quoteInto('blocks LIKE ? ', $block);
                $row = $this->DB->fetchRow($where);

                // Change the value of the blocks columns
                $rowBlocks = split(',', $row->blocks);
                foreach ($rowBlocks as $value)
                {
                    if($block != $value)
                    {
                        $blockArray = $value;
                    }
                }
                $row->blocks = $blockArray;

                // UPDATE the row in the database with new values
                $row->save();
As mentioned before, PHP tells me that the variable $row is not an object....shouldn't it be one??
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-26-2007, 10:32 AM
Junior Member
 
Join Date: Nov 2007
Posts: 1
Default

I do it this way:

Code:
$data = array(
    "field1" => "value1",
    "field2" => "value2"
);
$where = "id = " . $id;

$table = new Table();
$table->update($data, $where);
This is from Akra's DevNotes
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 11-28-2007, 05:25 AM
Junior Member
 
Join Date: May 2007
Posts: 9
Default

Thanks for the reply nomark.

The only thing is that I can't seem to access the row retrieved from the database using the object method. The documentation makes it clear that you should be able to access your row's column data using the object method...... Why this doesn't work for me, I don't know.

If you look at the link to the documentation I gave in my first post, you can see how they access the row data using object enumeration.

Does anyone know if this still exists in the Zend Framework?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 03:45 AM.