Reply
connection error
Old 04-19-2008, 01:43 PM connection error
Junior Talker

Posts: 1
Name: Jamie Oliver
hey I'm having a problem with a bit of code, it's long so I shortened it to the problem area.

Code:
class my_class extends Connect {
 var $connection;

 function set_conn() {
  //this creates a connection and works as tested by another script
  $this->connection = new Connect();
 }
 function get_conn() {
  return $this->connection();
 }
 function get_data( $query ) {
  if(!isset($this->connection)) {
   print "Error connecting to the database";
  } else {
   $i = 0;
   $get = $this->connection->Query($query);
   while($data = $this->connection->FetchArray($get)) {
    $result[$i++] = $data; 
   }
  }
   return $result;
 }
}
Then I have on my main script the following :

Code:
$config = new my_class();
$config->set_conn();
$functions = new my_class2();
$functions->grab('','','');//this is all ok
then I have another class that extends that class

Code:
class my_class2 extends my_class {
  function grab($type, $limit='10', $cat='1') {
  switch($type) {
   case 'most_viewed_home':
    $q = "some query";
    my_class::get_data($q); //or $this->get_data(q);?
   break;
  }
}
the problem is, for some reason $connection is no longer set when I use the grab function. all I get is Error connecting to the database. I'm sure I'm missing something silly, however I can't work it out. Can anybody see the problem?
loneguy is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 04-19-2008, 05:05 PM Re: connection error
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
the problem is that the conection is initialized for config object ... but when you declare the new object functions you dont have a conection made for that object ... hope this makes some sense

basicly they are 2 separate objects .... it doenst matter if the are from inherited classes. $config has a conection opened ... $functions doesnt ...

you can either make a new conection for the functions object .... or add an if in the get_data functions that checks if there is a conection opened if not opens it
__________________
If you like my posts ... TK is appreciated:)
Web Directory | Blog
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Reply     « Reply to connection error
 

Thread Tools

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 Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11450 seconds with 12 queries