Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2007
    Location
    Bronx, New York, United States
    Posts
    521
    Plugin Contributions
    3

    Default Retrieving the last ` LAST_INSERT_ID();` on a SQL Patch

    This is for PHP 8.2, ZC 1.5.8.

    I'm trying to write an auto-installer for a custom product type but I'm having a problem with the product type layout insert. The idea is that I use the last insert ID from product_types and insert that into the `product_type_layout` table as needed. But everytime I do so using the "Install SQL patch" in the admin area, I get an error saying something akin to:

    Code:
    You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '@insert_ID
    Or something like

    Code:
    FUNCTION zencart.1LAST_INSERT_ID does not exist :: INSERT INTO jg1_product_type_layout (configuration_title, configuration_key, configuration_value, configuration_description, product_type_id, sort_order, last_modified, date_added, use_function, set_function) VALUES ('Show Model Number', 'SHOW_PRODUCT_CARDS_FAB_INFO_MODEL', '0', 'Display Model Number on Product Info 0= off 1= on', LAST_INSERT_ID(), 1, NOW(), NOW(), NULL, 'zen_cfg_select_drop_down(array(array(\'id\'=>\'1\', \'text\'=>\'True\'),
    Here is the SQL code I'm trying to use:

    Code:
    INSERT INTO `product_types`     (`type_name`, `type_handler`, `type_master_type`, `allow_add_to_cart`, `default_image`, `date_added`, `last_modified`) 
        VALUES 
        ('Cards - Flesh and Blood', 'product_cards_fab', '1', 'Y', '', NOW(), NOW());
    
    
    INSERT INTO `product_type_layout` (`configuration_title`, `configuration_key`, `configuration_value`, `configuration_description`, `product_type_id`, `sort_order`, `last_modified`, `date_added`, `use_function`, `set_function`) VALUES ('Show Model Number', 'SHOW_PRODUCT_CARDS_FAB_INFO_MODEL', '0', 'Display Model Number on Product Info 0= off 1= on', LAST_INSERT_ID(), 1, NOW(), NOW(), NULL, 'zen_cfg_select_drop_down(array(array(\'id\'=>\'1\', \'text\'=>\'True\'), array(\'id\'=>\'0\', \'text\'=>\'False\')), '),
    Should I just use a $db->Execute instead or run something like this directly in PHPMyAdmin?

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Retrieving the last ` LAST_INSERT_ID();` on a SQL Patch

    I just ran this in SQL Patch without problem (only difference from yours was changed the last comma to a semicolon):
    Code:
    INSERT INTO `product_types`     (`type_name`, `type_handler`, `type_master_type`, `allow_add_to_cart`, `default_image`, `date_added`, `last_modified`) 
    VALUES ('Cards - Flesh and Blood', 'product_cards_fab', '1', 'Y', '', NOW(), NOW());
    INSERT INTO `product_type_layout` (`configuration_title`, `configuration_key`, `configuration_value`, `configuration_description`, `product_type_id`, `sort_order`, `last_modified`, `date_added`, `use_function`, `set_function`) VALUES ('Show Model Number', 'SHOW_PRODUCT_CARDS_FAB_INFO_MODEL', '0', 'Display Model Number on Product Info 0= off 1= on', LAST_INSERT_ID(), 1, NOW(), NOW(), NULL, 'zen_cfg_select_drop_down(array(array(\'id\'=>\'1\', \'text\'=>\'True\'), array(\'id\'=>\'0\', \'text\'=>\'False\')), ');
    You could optionally prefix it with something like the following on its own line before the first INSERT, but I didn't need to do that for it to work on my site.
    Code:
    #NEXT_X_ROWS_AS_ONE_COMMAND:3

    For reference, I'm using MariaDB 11.2.2 on this server, but this isn't anything unique to MariaDB vs MySQL, and it's not using anything "new" so should be fine to much older versions of MySQL and MariaDB.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 

Similar Threads

  1. v139g Cannot use the Sql install patch or import direct to data base
    By michelleodin in forum General Questions
    Replies: 1
    Last Post: 5 Jul 2014, 12:27 AM
  2. v150 SQL patch to insert the US & Non-US Shipping ?
    By Rony in forum Built-in Shipping and Payment Modules
    Replies: 3
    Last Post: 15 Jan 2013, 05:11 PM
  3. v139h Upload SQL Patch via phpMyAdmin in MySQL INSTEAD OF Amin-Tools-Install AQL patch ????
    By shags38 in forum Customization from the Admin
    Replies: 11
    Last Post: 20 Aug 2012, 04:19 AM
  4. v150 I was hoping to fix this problem with the SQL patch uploader.
    By sammirah in forum Upgrading to 1.5.x
    Replies: 11
    Last Post: 8 Apr 2012, 07:25 PM
  5. Error when using the SQL patch section.
    By arcanesanctuary in forum General Questions
    Replies: 1
    Last Post: 10 Oct 2009, 03:45 AM

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