Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-23-2008, 04:20 PM   PM User | #1
Bonker
New Coder

 
Join Date: Jul 2005
Location: Switzerland
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Bonker is an unknown quantity at this point
Macintosh How to use sqliteCreateAggregate inside class

This works fine:
PHP Code:
function GroupConcatStep(&$context$string$separator ',') {
  
$context .= $separator $string;
}
function 
GroupConcatFinalize(&$context) {
  return 
$context;
}

$Db = new PDO('sqlite: MyDb.sqlite');
$Db->sqliteCreateAggregate('GROUP_CONCAT''GroupConcatStep''GroupConcatFinalize'2); 
But I don't know how to do the same from inside a class. I don't get the names of the callback functions (methods) right. So the code below does not work:

PHP Code:
class MyClass {
  public function 
Connect() { 
    
$this->Db = new PDO('sqlite:'.$Path.'/'.$this->DbName);
    
$this->Db->sqliteCreateAggregate('GROUP_CONCAT''MyClass::GroupConcatStep''MyClass::GroupConcatFinalize'2);
  }
  public function 
GroupConcatStep(&$context$string$separator ',') {
    
$context .= $separator $string;
  }
  public function 
GroupConcatFinalize(&$context) {
    return 
$context;
  }

__________________
visit my website at www.speich.net
Bonker is offline   Reply With Quote
Old 08-23-2008, 06:23 PM   PM User | #2
Bonker
New Coder

 
Join Date: Jul 2005
Location: Switzerland
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Bonker is an unknown quantity at this point
Never mind, I just found out. This does the trick:

PHP Code:
$this->Db->sqliteCreateAggregate('GROUP_CONCAT', array($this'GroupConcatStep'), array($this'GroupConcatFinalize')); 
__________________
visit my website at www.speich.net
Bonker is offline   Reply With Quote
Old 08-23-2008, 09:09 PM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
That is correct, I'm glad you found the solution!
Just remember that callbacks always take class/object and parameters as array arguments and you'll be fine. The callBack definition is kind of difficult to find in PHP (hidden under pseudo types >.< http://ca3.php.net/manual/en/languag...types.callback), and their namespace usage has also been terribly documented (which I'm not worried about, there is still time). I have no idea why they decided to do it this way; I figure a function pointer definition or delegate would have been a far better solution since we would be able to typecast our own callback definitions.
Methinks we're stuck with this way now though >.<
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
callback, group_concat, method, sqlite

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:44 AM.


Advertisement
Log in to turn off these ads.