Re: [fw-general] Zend_Db_Table I have problems reading columns' alliases

2008-03-01 Thread James Dempster
:-) clever framework, so happy I use ZF!

On Sat, Mar 1, 2008 at 9:30 PM, Bill Karwin <[EMAIL PROTECTED]> wrote:

>
>
> JDempster wrote:
> >
> > Not 100% sure but I think you'll need
> >
> > $select->from($ct, array('max_id' => new Zend_Db_Expr('MAX(place_id)')
> ))
> >
>
> Actually, neither change is necessary.  Zend_Db_Select recognizes the
> pattern of parentheses, and assumes it should be a Zend_Db_Expr.  It also
> recognizes the pattern of "expr as alias" and assumes it should use the
> latter word as an alias as if you had given it as an assoc array key.
>
> Regards,
> Bill Karwin
> --
> View this message in context:
> http://www.nabble.com/Zend_Db_Table-I-have-problems-reading-columns%27-alliases-tp15779311s16154p15780877.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
>


-- 
/James


Re: [fw-general] Zend_Db_Table I have problems reading columns' alliases

2008-03-01 Thread Bill Karwin


JDempster wrote:
> 
> Not 100% sure but I think you'll need
> 
> $select->from($ct, array('max_id' => new Zend_Db_Expr('MAX(place_id)') ))
> 

Actually, neither change is necessary.  Zend_Db_Select recognizes the
pattern of parentheses, and assumes it should be a Zend_Db_Expr.  It also
recognizes the pattern of "expr as alias" and assumes it should use the
latter word as an alias as if you had given it as an assoc array key.

Regards,
Bill Karwin
-- 
View this message in context: 
http://www.nabble.com/Zend_Db_Table-I-have-problems-reading-columns%27-alliases-tp15779311s16154p15780877.html
Sent from the Zend Framework mailing list archive at Nabble.com.



Re: [fw-general] Zend_Db_Table I have problems reading columns' alliases

2008-03-01 Thread Bill Karwin


Marek Wawro wrote:
> 
> $select = $ct->select();
> $select->from($ct, 'MAX(place_id) as max_id')->where('shop_id = ?', 0)- 
>  >group('shop_id');
> $max = $ct->fetchRow($select);
> 
> When i am trying to read $max->max_id i am getting exception that this  
> column is not existing
> 

I just tried the code that you gave above, and it works for me and gives no
errors.  I'm using ZF 1.5 from the trunk, on Windows XP with PHP 5.2.5.

I believe you have left something out of your description of the issue.

Regards,
Bill Karwin

'test', 'username'=>'root',
'password'=>'root'));

// table `ct` exists in MySQL test database and has sample data
class ct extends Zend_Db_Table_Abstract { }

$ct = new ct($db);

$select = $ct->select();
$select->from($ct, 'MAX(place_id) as max_id')->where('shop_id = ?',
0)->group('shop_id');
$max = $ct->fetchRow($select);

print_r($max->toArray()); // array contains [max_id] => 4

print "max_id = " . $max->max_id . "\n"; // no error

$max->max_id = 24; // no error (but don't try to save this change)

-- 
View this message in context: 
http://www.nabble.com/Zend_Db_Table-I-have-problems-reading-columns%27-alliases-tp15779311s16154p15780855.html
Sent from the Zend Framework mailing list archive at Nabble.com.



Re: [fw-general] Zend_Db_Table I have problems reading columns' alliases

2008-03-01 Thread James Dempster
Not 100% sure but I think you'll need

$select->from($ct, array('max_id' => new Zend_Db_Expr('MAX(place_id)') ))
// et cetera


On Sat, Mar 1, 2008 at 6:27 PM, Tobias Gies <[EMAIL PROTECTED]>
wrote:

> Hey Marek,
>
> You should have read on.
> What you want can be done using the following code:
>
> $select->from($ct, array('max_id' => 'MAX(place_id)'))
> // et cetera
>
> Best regards,
> Tobias
>
> --
> Sent from my iPhone
>
> Am 01.03.2008 um 19:15 schrieb Marek Wawro <[EMAIL PROTECTED]>:
>
> Hi,I am having problems to call MAX function in mysql using
> zend_db_table_abstract
>
> Writing that code I based on: 
> 
> http://framework.zend.com/manual/en/zend.db.table.html example 10.95
>
> here is code snipet where  $ct extands Zend_Db_Table_Abstract
> $select = $ct->select();
> $select->from($ct, 'MAX(place_id) as max_id')->where('shop_id = ?', 0
> )->group('shop_id');
> $max = $ct->fetchRow($select);
>
> When i am trying to read $max->max_id i am getting exception that this
> column is not existing
>
>
>
> Thank you for help
>
> ps:
> Here is var_dump of $max variable
>
> object(Zend_Db_Table_Row)#47 (8) {
>   ["_data:protected"]=>
>   array(1) {
> ["max_id"]=>
> int(4)
>   }
>   ["_cleanData:protected"]=>
>   array(1) {
> ["max_id"]=>
> int(4)
>   }
>   ["_modifiedFields:protected"]=>
>   array(0) {
>   }
>   ["_table:protected"]=>
>   object(Content)#126 (13) {
> ["_name:protected"]=>
> string(7) "content"
> ["_primary:protected"]=>
> array(1) {
>   [1]=>
>   string(10) "content_id"
> }
> ["_db:protected"]=>
> object(Zend_Db_Adapter_Mysqli)#37 (9) {
>   ["_numericDataTypes:protected"]=>
>   array(16) {
> [0]=>
> int(0)
> [1]=>
> int(1)
> [2]=>
> int(2)
> ["INT"]=>
> int(0)
> ["INTEGER"]=>
> int(0)
> ["MEDIUMINT"]=>
> int(0)
> ["SMALLINT"]=>
> int(0)
> ["TINYINT"]=>
> int(0)
> ["BIGINT"]=>
> int(1)
> ["SERIAL"]=>
> int(1)
> ["DEC"]=>
> int(2)
> ["DECIMAL"]=>
> int(2)
> ["DOUBLE"]=>
> int(2)
> ["DOUBLE PRECISION"]=>
> int(2)
> ["FIXED"]=>
> int(2)
> ["FLOAT"]=>
> int(2)
>   }
>   ["_stmt:protected"]=>
>   object(Zend_Db_Statement_Mysqli)#82 (12) {
> ["_stmt:protected"]=>
> object(
>
>


-- 
/James


Re: [fw-general] Zend_Db_Table I have problems reading columns' alliases

2008-03-01 Thread Tobias Gies

Hey Marek,

You should have read on.
What you want can be done using the following code:

$select->from($ct, array('max_id' => 'MAX(place_id)'))
// et cetera

Best regards,
Tobias

--  
Sent from my iPhone


Am 01.03.2008 um 19:15 schrieb Marek Wawro <[EMAIL PROTECTED]>:


Hi,
I am having problems to call MAX function in mysql using  
zend_db_table_abstract


Writing that code I based on: http://framework.zend.com/manual/en/zend.db.table.html 
 example 10.95


here is code snipet where  $ct extands Zend_Db_Table_Abstract

$select = $ct->select();
$select->from($ct, 'MAX(place_id) as max_id')->where('shop_id = ?',  
0)->group('shop_id');

$max = $ct->fetchRow($select);

When i am trying to read $max->max_id i am getting exception that  
this column is not existing




Thank you for help

ps:
Here is var_dump of $max variable

object(Zend_Db_Table_Row)#47 (8) {
  ["_data:protected"]=>
  array(1) {
["max_id"]=>
int(4)
  }
  ["_cleanData:protected"]=>
  array(1) {
["max_id"]=>
int(4)
  }
  ["_modifiedFields:protected"]=>
  array(0) {
  }
  ["_table:protected"]=>
  object(Content)#126 (13) {
["_name:protected"]=>
string(7) "content"
["_primary:protected"]=>
array(1) {
  [1]=>
  string(10) "content_id"
}
["_db:protected"]=>
object(Zend_Db_Adapter_Mysqli)#37 (9) {
  ["_numericDataTypes:protected"]=>
  array(16) {
[0]=>
int(0)
[1]=>
int(1)
[2]=>
int(2)
["INT"]=>
int(0)
["INTEGER"]=>
int(0)
["MEDIUMINT"]=>
int(0)
["SMALLINT"]=>
int(0)
["TINYINT"]=>
int(0)
["BIGINT"]=>
int(1)
["SERIAL"]=>
int(1)
["DEC"]=>
int(2)
["DECIMAL"]=>
int(2)
["DOUBLE"]=>
int(2)
["DOUBLE PRECISION"]=>
int(2)
["FIXED"]=>
int(2)
["FLOAT"]=>
int(2)
  }
  ["_stmt:protected"]=>
  object(Zend_Db_Statement_Mysqli)#82 (12) {
["_stmt:protected"]=>
object(