Google Groups Home
Help | Sign in
Can't execute SQL statment in Model constructor?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
bentryster@gmail.com  
View profile
(1 user)  More options Apr 15 2006, 10:37 am
From: "bentrys...@gmail.com" <bentrys...@gmail.com>
Date: Sat, 15 Apr 2006 07:37:20 -0700
Local: Sat, Apr 15 2006 10:37 am
Subject: Can't execute SQL statment in Model constructor?
I want to set the MySQL database connection to use utf8 encoding. So I
overide the App_Model constructor like this:

class AppModel extends Model {
 function __construct()
  {
    $this->execute("Set NAMES 'UTF8'");
    parent::__construct();
  }

}

And then I got this error:
Fatal error: Call to a member function fetchAll() on a non-object in
D:\php-5.0.4-Win32\PHP_Script\PHP_CAKE\cake\libs\model\model_php5.php
on line 1143

But I add the execute statment in the other member function will be ok.
I think there is some object (maybe the database connection) hasn't
been created when the __construct() execute. Am I right? And How can I
slove this problem?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
nate  
View profile
(2 users)  More options Apr 15 2006, 2:28 pm
From: "nate" <nate.ab...@gmail.com>
Date: Sat, 15 Apr 2006 18:28:17 -0000
Local: Sat, Apr 15 2006 2:28 pm
Subject: Re: Can't execute SQL statment in Model constructor?
You're calling the method before the database connection has been
established.  Try this instead:

  function __construct()
  {
    parent::__construct();
    $this->execute("Set NAMES 'UTF8'");
  }


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bentryster@gmail.com  
View profile
(1 user)  More options Apr 15 2006, 8:13 pm
From: "bentrys...@gmail.com" <bentrys...@gmail.com>
Date: Sat, 15 Apr 2006 17:13:03 -0700
Local: Sat, Apr 15 2006 8:13 pm
Subject: Re: Can't execute SQL statment in Model constructor?

nate :

It works! Thanks!


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
matsch  
View profile
(2 users)  More options Apr 23 2006, 11:27 am
From: "matsch" <matthias.schm...@villatrauma.de>
Date: Sun, 23 Apr 2006 08:27:13 -0700
Local: Sun, Apr 23 2006 11:27 am
Subject: Re: Can't execute SQL statment in Model constructor?
hi nate,
right. this works but then a little problem occured:
all models (which extends AppModel) have not been loaded correctly
anymore.

the following changes solved the problem for me:

function __construct($id=false, $table=null, $ds=null) {
    parent::__construct($id, $table, $ds);
    $this->execute( "Set NAMES 'UTF8'" );

}

matthias

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bentryster@gmail.com  
View profile
 More options Apr 23 2006, 8:48 pm
From: "bentrys...@gmail.com" <bentrys...@gmail.com>
Date: Sun, 23 Apr 2006 17:48:33 -0700
Local: Sun, Apr 23 2006 8:48 pm
Subject: Re: Can't execute SQL statment in Model constructor?
Oh, I use the default parameters in all the Model , so there is no side
effects to me. I think matsch's mothod is more stable.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google