zend-db

Zend framework group by

Hey folks! I'm trying to do a group by using Zend framework. Here's my code: $table = new TableClass(); $select = $table->select(); $select->from ("table", array("date", "column1" => "sum(column1)")); $select->group ( array ("date") ); $results = $table->fetchAll ($select); $result = $results[0]; $date = $result->date; $column1 = $resu...

[zend][db] fetchAll with multiple variables

Hi everybody, I'm trying to use fetchAll on a query that has 2 variables. I can't figure out the syntax. I can manage with only 1 variable: $sql = "SELECT * FROM mytable WHERE field1 = ?"; $this->_db->fetchAll($sql,$value1); # that works However I'm having some issues when query has multiple variables $sql = "SELECT * FROM mytable ...

Zend_DB error : Mysqli statement execute error : Prepared statement needs to be re-prepared

Hello, the full error is "Zend_Db_Statement_Mysqli_Exception: Mysqli statement execute error : Prepared statement needs to be re-prepared" It occurs only on our unit tests server, but not on all run (it run tests every hour), and not on all test wich use database. We only have 111 PHPunit tests. The test server is a Linux Centos5 with...

Zend DB and encoding

Hi guys I have just encountered something rather strange, I use the Zend Framework 1.10 with the Zend_Db_Table module to read some data from a databse. The database itself, the table and the fields in question all have their collation set to "utf8_general_ci" and all special chars appear correctly formatted in the DB when checked with p...

Zend_Db subquery

Hi Everyone, I've been trying to construct a sql query with ZendFW, but I cant seem to get it to function like I want to (or function at all). This is the query that works that I'm trying to build with zend_db select() SELECT tc.trip_title, td.ID, td.trip_id, (SELECT count(*) FROM 'trips_invites' ti WHERE ti.destination_id=td.ID ...

How can I join tables in Zend while using a class that inherits from Zend_Db_Table_Row_Abstract?

I have a class that extends Zend_Db_Table lets call it 'Users' that uses the class 'User' (inheriting from Zend_Db_Table_Row_Abstract) as its rowClass. I need it this way because User has additional methods that I use. As far as I know it is not possible to join tables inside my Users class so I use: $query = $db->select(); ...

Zend DB Selecting constants - columns that do not exist in table

Hey I'm trying to do this query using Zend DB select but I'm not able to do so This is the sql query select shopping_id,shopping_details,"friend" as type from shopping Notice here how I'm specifying "friend" as type and friend is not a column in the shopping table. Now how do I do this in Zend. I have tried this but it gives me an...

Zend_Db and Models

Currently I have about 40 models and whenever I have needed to do an insert its always just been on a single model, so I have been happy to just use my class model which extends Zend_Db_Table_Abstract class Model extends Zend_Db_Table_Abstract However, now one of my requirements is to read a CSV file and normalize it into my database....

Zend Db Field Comments

Hi All, does anyone know if you can get individual field comments from mysql using Zend Db. What im working on is a registration form that gets all its fields from the db table. At the moment im using the field names to generate the labels for the form elements however it would be much better to get this data from the information_schema...

Zend Framework: How Do I 'auto' generate a SQL query correctly

I want to generate the following SQL: SELECT `rc`.*, `c`.`name` FROM `RunConfigurations` AS `rc` INNER JOIN `Clients` AS `c` ON rc.client_id = c.id WHERE (rc.client_id = ?) ORDER BY `rc`.`config_name` ASC However I am getting: SELECT `rc`.*, `c`.* FROM `RunConfigurations` AS `rc` INNER JOIN `Clients` AS `c` ON rc.client_id = c.id WHE...

Where clause with Zend_Db not working as expected

I am getting an error: Message: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%'Chinese'%) ORDER BYtext_idDESC LIMIT 10' at line 2 caused by this line of code $select = $this->_db->select('')...

Complex query implying dates

Hi, I'd like to return the customers from Magento who where created the day before OR who where updated the day before. I tried to play with addFieldToFilter, without any success. I also tried to manipulate Zend_Db_Select, no success. So now I'm stuck! Here are some of my tries : $customer = Mage::getModel('customer/customer'); $cust...

MySQL remove space before order by clause

Hi all. I have a table full of "title" that I want to order by title. Problem is a lot of them have a empty space before the title. I am thinking of writting a php script to fix it all (super easy) but I was curious how could I do: SELECT * FROM products ORDER BY title But at the same time trimming the title so it doesnt order on the ...

Why should I use Doctrine over Zend_Db ?

I use Zend_Db in some project, I discover Doctrine there is a while but never actually used it. What are the advantage of Doctrine over Zend_Db ? What are the benefits to use Doctrine ? By the way, is it easy to use Doctrine with Zend Framework 1.10.7? Integration and use with the other component ? As it doesn't seem to exist a Doctrin...

Zend PDO error - how can I debug it?

I have a weird problem using Zend Framework and Mysql. I generated a query: SELECT events.idUser, szForename, szLastname, readers.szName, idZoneFrom, events.dtTime FROM events, users, readers WHERE events.idUser = users.idUser AND events.idReader = readers.idReader AND dtTime >= '2010:02:15 0:00:00' AND dtTime < '2010:02:16 0:00:00' ORD...

Zend Framework DB update

Hello friends. Is there something similar to save for the update task? If I want to save a new record I just do it: $data_from_post = $_POST; $newUser = $usersDb->fetchNew(); $newUser->setFromArray($data_from_post); $newUser->save(); Is there something for the update task? Thanks and best regard´s. ...

Unit testing a class that returns SQL

I'm trying to use PHPUnit to unit test some class methods that return SQL. These classes should work with any Zend_Db adapter, so I would like the tests to do the same. My tests look a little like this: public function testEtcGeneratesCorrectSQL() { $model = new ClassBeingTested(); // do some stuff $sql = $model->__toStrin...

Zend db table find just like fetchRow

Hello my friends, I´m using find() to retrieve a value from the database, but It returns an array with the objects, I would like that it return to me just the object like fetchRow returns, is there any change or similar thing to do? Thanks, and best regard´s. ...

Zend-framework DB: OR instead of AND operator

Hi, have such zend query: $select = $this->_table ->select() ->where('title LIKE ?', '%'.$searchWord.'%') ->where('description LIKE ?', '%'.$searchWord.'%') ->where('verified=1 AND activated=1'); In other words it looks like: SELECT `some_table`.* FROM `some_table` WHERE ...

zend framework select join error getTable()

I am trying to implement this method in my model: class Application_Model_MenuProfilesProducts extends Zend_Db_Table_Abstract { protected $_name = 'menu_profiles_products'; public function fetchProducts($profileID) { $select = Zend_Db_Table::getDefaultAdapter()->select() ->from(array('mpp' => 'men...