+ Reply to Thread
Results 1 to 5 of 5

Thread: QuoteInto to with multiple parameters

  1. #1
    dele454's Avatar
    dele454 is offline Member
    Join Date
    Jun 2008
    Posts
    49

    Default QuoteInto to with multiple parameters

    hi

    I need to query the database with 2 parameters from a URL :

    http://mainevent.com/admin/galleries...d/1/type/venue


    Code:
    public function getGalleryByIdType($requestType="", $requestID="")
                    {
                                   if($requestType ="event'){
                                   
                                      $db        = Zend_Registry::get('db');
                                       $sql       = $db->quoteInto("SELECT g.GalleryName, e.EventName
                                                       FROM Galleries  g  
                                                       LEFT JOIN EventGallery eg ON eg.GalleryID = g.GalleryID
                                                       LEFT JOIN Event e On e.EventID = eg.EventID
                                                       WHERE g.Type=? AND g.GalleryID=?" , $requestType,$requestID);
                           
                                                                                             
                                      $query     = $db->query($sql);
                                   
                                      $results   = $query->fetchAll();
                                     
                                      return $results;
                                }
                   
                   
                    }
    It seems the quoteInto function only accepts a single parameter. It returns an empty array with no results. And the function doesnt support supplying parameters as an array of values. I came across this article:

    Modifying Zend_Db_Adapter_Abstract::quoteInto to accept multiple question marks at Amikelive | Technology Blog

    And this guy recommends modifying the function definition. I just want to know if this is the appropriate route to solving this. Thanks

  2. #2
    Tekerson is offline Senior Member
    Join Date
    Jul 2008
    Posts
    288

    Default

    The other option is to use bound parameters by passing the second parameter to query(). So you don't even need quoteInto(). Like this:
    Code:
    ...
    $sql       = 'SELECT g.GalleryName, e.EventName
                    ...
                    WHERE g.Type = :gType AND g.GalleryID = :gGalleryId';
                    
                    $query     = $db->query($sql, array(
                        'gType' => $gType,
                        'gGalleryId' => $gGalleryId,
                    ));
    You can have as many bound parameters as you want, unfortunately you can't use the same one multiple times in the query (unless that's changed since last I looked).
    Brenton Alker
    PHP Developer - Brisbane, Australia

    blog.tekerson.com | twitter.com/tekerson | brenton.mp

  3. #3
    dele454's Avatar
    dele454 is offline Member
    Join Date
    Jun 2008
    Posts
    49

    Default

    Quote Originally Posted by Tekerson View Post
    The other option is to use bound parameters by passing the second parameter to query(). So you don't even need quoteInto(). Like this:
    Code:
    ...
    $sql       = 'SELECT g.GalleryName, e.EventName
                    ...
                    WHERE g.Type = :gType AND g.GalleryID = :gGalleryId';
                    
                    $query     = $db->query($sql, array(
                        'gType' => $gType,
                        'gGalleryId' => $gGalleryId,
                    ));
    You can have as many bound parameters as you want, unfortunately you can't use the same one multiple times in the query (unless that's changed since last I looked).
    Thanks but then i am not quoting any of those values! Doesnt that open me to sql injection attacks?

  4. #4
    Tekerson is offline Senior Member
    Join Date
    Jul 2008
    Posts
    288

    Default

    Nope, the bound parameters are inserted by creating a prepared statement and executing it (or a facsimile of, if prepared statements are not available in your database/adapter).
    Last edited by Tekerson; 08-12-2008 at 06:13 AM. Reason: Grammar
    Brenton Alker
    PHP Developer - Brisbane, Australia

    blog.tekerson.com | twitter.com/tekerson | brenton.mp

  5. #5
    serbanghita is offline Junior Member
    Join Date
    Jul 2008
    Posts
    2

    Post re

    Tekerson - i have a question related to what you said

    [PHP]
    $arr = array('some_id' => (int)$some_id, 'name' => $name, 'name2' => $name2);
    $this->db->update('table', $arr, 'id ='.(int)$id);
    [/PHP]

    I am only doing trim() on $name and $name2, is this query safe? How should i escape the vars? Is Zend_Db doing it automagically?

    Thanks!

+ Reply to Thread

Similar Threads

  1. $this->url without parameters
    By jerz in forum General Q&A on Zend Framework
    Replies: 2
    Last Post: 07-08-2009, 06:46 AM
  2. How to read parameters from URL in ZF?
    By keenlio in forum Model-View-Controller (MVC)
    Replies: 7
    Last Post: 10-08-2008, 06:02 PM
  3. xml-rpc server parameters
    By emerson999 in forum Web & Web Services
    Replies: 0
    Last Post: 10-07-2008, 06:25 PM
  4. quoteInto errors
    By MightyMouse in forum Databases
    Replies: 1
    Last Post: 10-03-2008, 02:11 AM
  5. MVC ignoring my parameters?
    By clone45 in forum Installation & Configuration
    Replies: 0
    Last Post: 10-16-2007, 07:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts