Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [ZendFramework]Zend_Db_Select where
nospor
post
Post #1





Grupa: Moderatorzy
Postów: 36 559
Pomógł: 6315
Dołączył: 27.12.2004




Chce uzyskac zapytanie (przykład z manuala):
  1. <?php
  2. //   SELECT product_id, product_name, price
  3. //   FROM "products"
  4. //   WHERE (price < 100.00 OR price > 500.00)
  5. //     AND (product_name = 'Apple')
  6.  
  7. $minimumPrice = 100;
  8. $maximumPrice = 500;
  9. $prod = 'Apple';
  10.  
  11. $select = $db->select()
  12.             ->from('products',
  13.                    array('product_id', 'product_name', 'price'))
  14.             ->where("price < $minimumPrice OR price > $maximumPrice")
  15.             ->where('product_name = ?', $prod);
  16. ?>

zastosowali: ->where("price < $minimumPrice OR price > $maximumPrice")
Chcialbym jednak uzyc bindowania i zrobic tak
  1. <?php
  2. ->where("price < ? OR price > ?", $minimumPrice, $maximumPrice);
  3. ?>

Oczywiscie to nie zadziala, bo where() przyjmuje tylko jedą wartosc do bindowania. W kodzie ani w dokumentacji nie znalazlem tego, a nie chce mi sie wierzyc by nie pomysleli o tym przy where()... Zapodanie tablicy wartosci tez nie dziala.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
konys
post
Post #2





Grupa: Zarejestrowani
Postów: 100
Pomógł: 7
Dołączył: 5.11.2005

Ostrzeżenie: (0%)
-----


Cytat
nie chce mi sie wierzyc by nie pomysleli o tym przy where()...

Tak na szybko przejrzalem kod i wychodzi, ze Zend_Db_Select::where wywoluje Zend_Db_Select::_where gdzie umieszczony zostal warunek:
Kod
        if ($value !== null) {
            $condition = $this->_adapter->quoteInto($condition, $value, $type);
        }

Z kolei Zend_Db_Adapter_Abstract::quoteInto($text, $value, $type, $count) ma parametr $count
Cytat
@param integer $count OPTIONAL count of placeholders to replace

Z tego co rozumiem, gdyby w _where umiescic cos podobnego do:
Kod
        if ($value !== null) {
            $count = is_array($value) ? count($value) : null;
            $condition = $this->_adapter->quoteInto($condition, $value, $type, $count);
        }

to mialoby szanse zadzialac. Tylko taki strzal (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 7.10.2025 - 00:08