I am trying to do a group using the Zend Framework, here my code is:
$ table = new tableclose (); $ Select = $ Table-> Choose (); $ Select- & gt; From ("Table", Array ("Date", "Column 1" = & gt; "Yoga (Column 1)")); $ Selection- & gt; Group (array ("date")); $ Result = $ table- & gt; Get All (select $); $ Result = $ result [0]; $ Date = $ result-> Date; $ Column1 = $ result-> Column 1;
The tableclass extends to 'Zend_Db_Table_Abstract'.
I can see the query by looking at mysql query logs. The query is well-formed - column 1 is named in the query and if the query runs in mysql workbench the result looks fine.
I can not access the data in 'column 1' - I always get this exception:
Ignored exceptions with the message 'Zend_Db_Table_Row_Exception' in the 'specified column' column 1 "in the row '
But I can use the date column without any problem.
I tried:
-
array index By accessing the column: You get an exception on the [$] result [0] (index can not reach the column).
-
One level Do not use aliases: $ select-> ("table", array ("date", "amount (column1)")); $ column1 = $ result ["sum (column1)"]; You get an exception (any such column "zodiac (" column 1) ").
-
Throwing in a Zend_Db_Expr:" column1 "=> New Zend_Db_Expr (" sum (column1) ") but It does not help.
I have noticed that some other examples use the column names of unified functions, instead of "zodiac 1 (column1)" "Column 1" but I like this Do not think - there is no consolidated work in the query, so mysql does not know what to do with it.
Any help appreciated. First, Zend_Db_Select (and a quick tip to work in detail, Zend_Db_Table_Select), you have toString method. You can see the SQL generated. It is important to verify that your code generates the right query before working with the result set:
$ select = $ table-> Choose (); $ Select- & gt; From ("Table", Array ("Date", "Column 1" = & gt; "Yoga (Column 1)")); $ Selection- & gt; Group (array ("date")); $ Sql = (string) $ select; // Retrieve SQL as a string
or simply
die (select $); // print sql
I have written the following test script using your example and there is no problem in it:
class table Zend_Db_Table_Abstract {protected $ _primary = 'id'; Protected $ _name = 'Table'; } $ Db = Zend_Db :: factory ('Pdo_Mysql', array ('dbname' = & gt; 'test', 'username' = & gt; 'root', 'password' = & gt; '', 'host' = & Gt; 'localhost')); $ Table = new table ($ db); $ Select = $ Table-> Choose (); $ Select-> ($ table, array ("date", "column1" = New Zend_Db_Expr ("sum (column1)"))); $ Selection- & gt; Group (array ("date")); $ Sql = (string) $ select; $ Sql per second; $ Result = $ table- & gt; Get All (select $); $ Result = $ result [0]; $ Date = $ result-> Date; $ Column1 = $ result-> Column 1; Echo & lt; Br> '. $ Date ':'. $ Column1;
Use the Zend_Debug :: Dump ($ result); Inspecting the data inside Zend_Db_Table_Row if necessary.
In my case the SQL generated is as follows:
select `table```````, amount (column 1) from AS column ' `Date` by group`
Comments
Post a Comment