Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2012
    Posts
    412
    Plugin Contributions
    0

    Default $db->Execute Question

    Ran across the following code in the sales report plugin:
    Code:
            $order_info = $db->Execute(
                "SELECT o.currency, o.currency_value, o.order_total
                   FROM " . TABLE_ORDERS . " o
                  WHERE o.orders_id = $oID
                  LIMIT 1"
            );
    Note that the php variable $oID is enclosed in the long double-quoted phrase. I always thought a query like this should be written as:
    Code:
            $order_info = $db->Execute(
                "SELECT o.currency, o.currency_value, o.order_total
                   FROM " . TABLE_ORDERS . " o
                  WHERE o.orders_id = " . $oID . 
                  " LIMIT 1"
            );
    .

    Does the Execute method really substitute the value of $oID for the text "$oID"?

    Sorry, I can't follow the code in Execute to answer the above question.

  2. #2
    Join Date
    Jan 2004
    Location
    N of San Antonio TX
    Posts
    9,154
    Plugin Contributions
    11

    Default Re: $db->Execute Question

    You might want to post over on the thread for that mod.

    https://www.zen-cart.com/showthread....es-report-2-0/

  3. #3
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,694
    Plugin Contributions
    9

    Default Re: $db->Execute Question

    Quote Originally Posted by Dave224 View Post
    Ran across the following code in the sales report plugin:
    Code:
            $order_info = $db->Execute(
                "SELECT o.currency, o.currency_value, o.order_total
                   FROM " . TABLE_ORDERS . " o
                  WHERE o.orders_id = $oID
                  LIMIT 1"
            );
    Note that the php variable $oID is enclosed in the long double-quoted phrase. I always thought a query like this should be written as:
    Code:
            $order_info = $db->Execute(
                "SELECT o.currency, o.currency_value, o.order_total
                   FROM " . TABLE_ORDERS . " o
                  WHERE o.orders_id = " . $oID . 
                  " LIMIT 1"
            );
    .

    Does the Execute method really substitute the value of $oID for the text "$oID"?

    Sorry, I can't follow the code in Execute to answer the above question.
    you have thought wrong. vars get evaluated in double quotes; they do not in single quotes.

    if your sql statement has no vars in it, it is best to use single quotes. if there are vars in it, use double quotes as in the original code.

    that would be the most efficient way to do it; although the results may not be noticeable.

    best.
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  4. #4
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,703
    Plugin Contributions
    123

    Default Re: $db->Execute Question

    > Does the Execute method really substitute the value of $oID for the text "$oID"?

    When a string is enclosed in double quotes (not single), PHP performs string interpolation.
    Do a websearch on "php string interpolation" to learn more.
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  5. #5
    Join Date
    Jun 2012
    Posts
    412
    Plugin Contributions
    0

    Default Re: $db->Execute Question

    Thank you all so much. I learn so much here. Donation on the way.
    Dave

 

 

Similar Threads

  1. v151 db Execute issue -- Undefined variable: $db
    By tmpinsnty in forum General Questions
    Replies: 14
    Last Post: 25 Apr 2018, 07:57 PM
  2. Execute API on successful order
    By max4u in forum All Other Contributions/Addons
    Replies: 21
    Last Post: 5 Oct 2012, 02:36 PM
  3. Amount of rows with $db->Execute?
    By joecooper in forum General Questions
    Replies: 3
    Last Post: 15 Feb 2012, 11:46 PM
  4. execute a javascript
    By JohnBoyCR in forum General Questions
    Replies: 2
    Last Post: 11 May 2009, 09:22 PM
  5. $db->Execute throwing error
    By artcoder in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 15 May 2008, 10:51 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
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR