Results 1 to 6 of 6

Thread: $db->query() not accepting this mysql query?

  1. #1
    twick100 is offline Sugar Community Member
    Join Date
    Jun 2011
    Posts
    30

    Default $db->query() not accepting this mysql query?

    This is the query

    $query =
    "SELECT f.name fname, f.state, f.city, f.id fid, cl.alt_asd_ida, cl.alt_asdd_idb, c.ave_amount, c.asd, c.name, cc.first_name, cc.last_name, cc.id cid, cc.phone_work
    FROM alt_facilities f
    INNER JOIN alt_facchem_c cl ON (f.id = cl.alt_facit_ida)
    INNER JOIN alt_chemicals c ON (cl.alt_fasad_idb = c.id)
    LEFT OUTER JOIN alt_f2334_c con ON (f.id = con.alt_56_ida)
    LEFT OUTER JOIN contacts cc ON (con.alt_asdds_idb = cc.id)
    WHERE c.name = 'lead'
    AND f.state IN ('AL','FL')
    ORDER BY fname;";

    $db = DBManagerFactory::getInstance();

    $result = $db->query($query);

    The problem is not with the query, I know this much for sure. I can run this exact query in a terminal for the database outside of PHP and it works perfect. When I run it via PHP with the DB class, it doesn't return anything.

    I know the problem has to do the with "IN" statement because it stopped working when I added that.

  2. #2
    gauts is offline Sugar Community Member
    Join Date
    Aug 2007
    Location
    France
    Posts
    27

    Default Re: $db->query() not accepting this mysql query?

    Hi

    did you try to echo $db->last_error;

    or did you check you log file, mysql errors should be logged.

    And in you query you wrote
    ORDER BY fname

    it should be
    ORDER BY f.name

    but maybe this is just when you've put this in the forum.

    hope this can help
    Gauthier GENEAU
    CIGO SAS
    10 grand rue 68280 Logelheim (France)
    http://www.cigo-developpement.fr

  3. #3
    sts's Avatar
    sts
    sts is offline Sugar Community Member
    Join Date
    Aug 2010
    Posts
    978

    Default Re: $db->query() not accepting this mysql query?

    If you are sure that the IN statement is problematic (or to test if this is the case) you could use 'or' instead (at least if your IN does not contain too much alternatives ...):
    AND f.state IN ('AL','FL')
    AND (f.state = 'AL' OR f.state = 'FL')
    Stefan Ulrich Sauer
    System Analyst

    Devoteam Danet GmbH
    Gutenbergstraße 10
    D-64331 Weiterstadt
    Germany
    email: Stefan-Ulrich.Sauer@devoteam.com
    http://www.devoteam.de

  4. #4
    snikwahj is offline Sugar Community Member
    Join Date
    Dec 2007
    Posts
    38

    Default Re: $db->query() not accepting this mysql query?

    Quote Originally Posted by twick100 View Post
    ...
    ORDER BY fname;";
    ...
    If the query you posted has been copy & pasted from your code as above then the error is probably that you have the semi-colon included at the end of it (between fname and the closing double quote of the string). You do not need to include the semi colon in the query string when calling a query in the bean. You only need that when you are running a SQL query in the terminal window.

    The query string in your code should look like this:

    PHP Code:
    $query =
    "SELECT f.name fname, f.state, f.city, f.id fid, cl.alt_asd_ida, cl.alt_asdd_idb, c.ave_amount, c.asd, c.name, cc.first_name, cc.last_name, cc.id cid, cc.phone_work
    FROM alt_facilities f
    INNER JOIN alt_facchem_c cl ON (f.id = cl.alt_facit_ida)
    INNER JOIN alt_chemicals c ON (cl.alt_fasad_idb = c.id)
    LEFT OUTER JOIN alt_f2334_c con ON (f.id = con.alt_56_ida)
    LEFT OUTER JOIN contacts cc ON (con.alt_asdds_idb = cc.id)
    WHERE c.name = 'lead'
    AND f.state IN ('AL','FL')
    ORDER BY fname"

    Regards,

    JH.

  5. #5
    rafael.q.g@hotmail.com's Avatar
    rafael.q.g@hotmail.com is offline Sugar Community Member
    Join Date
    Jun 2011
    Location
    Florianópolis - Brazil
    Posts
    782

    Default Re: $db->query() not accepting this mysql query?

    You already tried to run this query directly on databaser sever to check whether code sintax is been interpretted correctly? Maybe there is easy to debug these issues.
    Rafael Queiroz Gonçalves
    Advanced OMG UML Certified Professional
    Sun Certified Enterprise Architect for the Java Platform
    Sun Certified Programmer for the Java 2 Platform
    IBM Certified Advanced Application Developer - Lotus Notes and Domino
    IBM Certified Application Developer - IBM WebSphere Portlet Factory
    Computer Science Mastering / UFSC - PPGCC

  6. #6
    twick100 is offline Sugar Community Member
    Join Date
    Jun 2011
    Posts
    30

    Default Re: $db->query() not accepting this mysql query?

    Sorry for my late response. I figured it out. I was getting the single quotes from the post data. Instead I added them in server side. I assume there is some sort of security feature that prevented the quotes from posting with proper encoding.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 2010-12-20, 04:08 PM
  2. Replies: 3
    Last Post: 2008-09-30, 08:43 PM
  3. Replies: 2
    Last Post: 2006-10-20, 12:00 AM
  4. Query Failed: ::MySQL error 1065: Query was empty
    By suruchi in forum Developer Help
    Replies: 1
    Last Post: 2006-01-21, 03:16 PM
  5. Query Failed: ::MySQL error 1065: Query was empty
    By suruchi in forum General Discussion
    Replies: 0
    Last Post: 2006-01-21, 12:04 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
  •