I suppose your code is part of the model calss, but not controller as
getDataSource() is model method. I'm calling it from controller and
result is NULL, even with $this->Model->getDataSource()->error.
The decision was to use $this->getDboSource()->error in model class,
in onError() callback function - it works fine. I presumed that model
and related objects are destructed before passing the action to the
controller and that's the reason I can't access DboMysql object
variables.

On Sep 17, 1:04 pm, "Dr. Loboto" <[email protected]> wrote:
> I use $this->getDataSource()->error. It holds last error as string
> "errno: error"
>
> On Sep 16, 3:01 pm, senser <[email protected]> wrote:
>
> > Dr. Loboto, I tried your suggestion and error for undefined property
> > $connection has gone away, but the method lastError() returns a NULL.
> > Here is the code snippet from the controller:
> > $this->Model->create($data);
> > $db_object=$this->Model->getDataSource();
> > $this->Model->saveAll($data, array('validate'=>true, 'atomic'=>true));
> > pr($db_object->lastError());
>
> > On Sep 16, 6:12 am, "Dr. Loboto" <[email protected]> wrote:
>
> > > You should call lastError() on model datasource: $this->getDataSource
> > > ()->lastError(), same for other DboMysql methods.
>
> > > On Sep 15, 6:39 pm, senser <[email protected]> wrote:
>
> > > > Hello,
>
> > > > I'm trying to find a way to get errors occurred when executing SQL
> > > > queries for adding, editing or deleting rows and show them in view.
> > > > There is a method in DboMysql called lastError() but when calling it I
> > > > receive an error: "Undefined property: ***::$connection". There is a
> > > > callback method onError() in model too, but I can't find how to use it
> > > > to receive sql error.
> > > > For example: User want to save new row in database table. Row data
> > > > passes validation rules but when Cake tries to save it to mysql,
> > > > server returns an error for duplicate entry in some row field - I need
> > > > to show that error to user.
>
> > > > Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to