Results 1 to 3 of 3

Thread: Help building a Query for a Hook.

  1. #1
    chrislynch8's Avatar
    chrislynch8 is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Cork, Ireland
    Posts
    747

    Default Help building a Query for a Hook.

    I'm am trying to run a query in a Logic Hook and I am using a field from the CRM that could contain ' so I need to escape this in the query so the SQL syntax is correct. I tried the following but Sugar is escaping my escapes I beleive.

    PHP Code:
    $name str_replace("'","\'",$bean->name);
    $query 'SELECT * FROM table WHERE name = $name AND number = "'.$bean->number.'"'
    Should I be using a different function to escape my name field.

    Rgds
    Chris

    **********************************
    Sloved
    **********************************

    Using $bean->db->quote($bean->name) I was able to correctly add my escape characters as required by Mysql.
    Last edited by chrislynch8; 2010-10-04 at 02:19 PM.
    Linkedin Profile:Chris Lynch

    FDC IT Solutions
    FDC House
    Wellington Road
    Cork
    Ireland

  2. #2
    robertbmirth is offline Sugar Community Member
    Join Date
    Jun 2010
    Location
    Irvine, CA
    Posts
    345

    Default Re: Help building a Query for a Hook.

    In general, there's also the built in PHP function mysql_real_escape_string() but I guess its better to use Sugar's function as it is probably database type independent (i.e. I'm guessing it works on postgres, MSSQL, etc as well). Thanks for the info though.
    Robert Beckman
    Software Engineer
    Mirth Corporation

  3. #3
    chrislynch8's Avatar
    chrislynch8 is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Cork, Ireland
    Posts
    747

    Default Re: Help building a Query for a Hook.

    Hi,

    I did try the built in php function but it looks like sugar was then removeing the escapes. So that why I used the Sugars Function instead.

    Rgds
    Chris
    Linkedin Profile:Chris Lynch

    FDC IT Solutions
    FDC House
    Wellington Road
    Cork
    Ireland

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Module Building
    By prodicalxxi in forum Help
    Replies: 3
    Last Post: 2010-11-03, 07:42 AM
  2. How to get query data in process_record hook
    By datasponge in forum Developer Help
    Replies: 7
    Last Post: 2010-02-24, 03:27 AM
  3. Db query problem from logic hook
    By ishaan in forum Developer Help
    Replies: 2
    Last Post: 2009-05-22, 08:02 PM
  4. How to write Database query in custom Hook?
    By shyam007 in forum Developer Help
    Replies: 1
    Last Post: 2009-03-27, 08:59 AM
  5. Building a new module in 4.5f
    By b0bcat2000 in forum General Discussion
    Replies: 5
    Last Post: 2007-02-12, 09:45 PM

Bookmarks

Posting Permissions

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