Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [ZendFramework]Zend_Db_Select where
nospor
post
Post #1





Grupa: Moderatorzy
Postów: 36 557
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
ziqzaq
post
Post #2





Grupa: Zarejestrowani
Postów: 428
Pomógł: 128
Dołączył: 17.06.2007

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


Cytat
If you need to combine terms together using OR, use the orWhere() method. This method is used in the same way as the where() method, except that the term specified is preceded by OR, instead of AND.

Edit: źródło

Ten post edytował ziqzaq 19.02.2009, 09:49:21
Go to the top of the page
+Quote Post
nospor
post
Post #3





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




a przeczytaj jeszcze raz przyklad z pierwszego posta i porownaj z tym co robi orWhere (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)

ps: moj przyklad jest pod tym co ty mi zacytowales (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)
Go to the top of the page
+Quote Post
ziqzaq
post
Post #4





Grupa: Zarejestrowani
Postów: 428
Pomógł: 128
Dołączył: 17.06.2007

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


Mea kulpa (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
wolditm
post
Post #5





Grupa: Zarejestrowani
Postów: 31
Pomógł: 2
Dołączył: 20.07.2005

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


  1. <?php
  2. $select = $db->select()
  3.            ->from('products', array('product_id', 'product_name', 'price'))
  4.            ->where("price < :minimumPrice OR price > :maximumPrice", array('minimumPrice' => $minimumPrice, 'maximumPrice' => $maximumPrice))
  5.            ->where('product_name = ?', $prod);
  6. ?>


?
Go to the top of the page
+Quote Post
nospor
post
Post #6





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




rozumiem ze to zwykły strzał? oczywiscie nie działa

" Invalid parameter number: no parameters were bound "
Go to the top of the page
+Quote Post
konys
post
Post #7





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
nospor
post
Post #8





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




Hehe, no tak, ale nie będę przecież modyfikował im frameworka. Przyjdzie nowa wersja i bede musial pamietac ze jakies zmiany robilem i ja nanosic na nową wersje
Go to the top of the page
+Quote Post
bigZbig
post
Post #9





Grupa: Zarejestrowani
Postów: 740
Pomógł: 15
Dołączył: 23.08.2004
Skąd: Poznań

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


Zawsze możesz spróbować czerpiąc z przykładu http://zendframework.com/manual/en/zend.db...tement.creating

a konkretnie

  1. <?php
  2. $select = $db->select()
  3.           ->from('products', array('product_id', 'product_name', 'price'))
  4.           ->where("price < :minimumPrice OR price > :maximumPrice")
  5.           ->where('product_name = :prodName');
  6. $stmt = new Zend_Db_Statement_Mysqli($db, (string) $select);
  7. $stmt->execute(array(':minimumPrice' => $minimumPrice, ':maximumPrice' => $maximumPrice, ':prodName' => $prod));
  8. $stmt->fetchAll();
  9. ?>


Pisałem na sucho więc nie wiem czy zadziała
Go to the top of the page
+Quote Post
nospor
post
Post #10





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




Jest to jakaś myśl.
Niestety uzywam tego $select do Zend_Paginator i coś czuję ze podane przez Ciebie rozwiązanie będzie się z tym gryzło.
Go to the top of the page
+Quote Post

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: 23.08.2025 - 05:28