Magento 2 - read and write connection for custom queryMagento get read or write connection for model / resource modelget generated Id from custom write connectionMagento 2 Customer Order Attribute SQL Error in ControllerMagento Read & Write Connection Close Manually NeededHow to write mysql update query in magento 2 format?Custom Connection to databaseHow and where to add join query in magento 2 for UI componentssql query in cms_block table in magento 2Magento 2 master slave connection for DBSQL Query for custom attribute

VHDL: Why is it hard to design a floating point unit in hardware?

Department head said that group project may be rejected. How to mitigate?

amsmath: How can I use the equation numbering and label manually and anywhere?

Meaning of "half-crown enclosure"

What is the required burn to keep a satellite at a Lagrangian point?

Why is unzipped file smaller than zipped file

Why do the i8080 I/O instructions take a byte-sized operand to determine the port?

Is it normal to "extract a paper" from a master thesis?

Why is this integration method not valid?

How would a physicist explain this starship engine?

How to become an Editorial board member?

Is the default 512 byte physical sector size appropriate for SSD disks under Linux?

Keeping the dodos out of the field

(For training purposes) Are there any openings with rook pawns that are more effective than others (and if so, what are they)?

How many wires should be in a new thermostat cable?

What is the winged creature on the back of the Mordenkainen's Tome of Foes book?

Can someone get a spouse off a deed that never lived together and was incarcerated?

Team member is vehemently against code formatting

What was the primary motivation for a historical figure like Xenophon to create an extensive collection of written material?

Why is the reciprocal used in fraction division?

What defines a person who is circumcised "of the heart"?

nginx conf: http2 module not working in Chrome in ubuntu 18.04

How to test if argument is a single space?

Is there an idiom that means that you are in a very strong negotiation position in a negotiation?



Magento 2 - read and write connection for custom query


Magento get read or write connection for model / resource modelget generated Id from custom write connectionMagento 2 Customer Order Attribute SQL Error in ControllerMagento Read & Write Connection Close Manually NeededHow to write mysql update query in magento 2 format?Custom Connection to databaseHow and where to add join query in magento 2 for UI componentssql query in cms_block table in magento 2Magento 2 master slave connection for DBSQL Query for custom attribute






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I am using Magento 2.2.5 EE. I need to write some custom queries Select and Insert



I know how to write custom query, its simple:



Create new connection:



$objectManager = MagentoFrameworkAppObjectManager::getInstance(); // Instance of object manager
$resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
$connection = $resource->getConnection();


Apply select query through this:



$tableName = $resource->getTableName('employee'); //gives table name with prefix
//Select Data from table
$sql = "Select * FROM " . $tableName;
$result = $connection->fetchAll($sql);


And Insert command using this:



//Insert Data into table
$sql = "Insert Into " . $tableName . " (emp_id, emp_name, emp_code, emp_salary) Values ('','XYZ','ABD20','50000')";
$connection->query($sql);


In magento 1.9, we just define "core_read" and "core_write" for our custom queries, it was that simple.



My question is, how Magento knows when to insert on master DB (write) and when to get data from read replica (read)? I mean the object for both commands is same.










share|improve this question






























    2















    I am using Magento 2.2.5 EE. I need to write some custom queries Select and Insert



    I know how to write custom query, its simple:



    Create new connection:



    $objectManager = MagentoFrameworkAppObjectManager::getInstance(); // Instance of object manager
    $resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
    $connection = $resource->getConnection();


    Apply select query through this:



    $tableName = $resource->getTableName('employee'); //gives table name with prefix
    //Select Data from table
    $sql = "Select * FROM " . $tableName;
    $result = $connection->fetchAll($sql);


    And Insert command using this:



    //Insert Data into table
    $sql = "Insert Into " . $tableName . " (emp_id, emp_name, emp_code, emp_salary) Values ('','XYZ','ABD20','50000')";
    $connection->query($sql);


    In magento 1.9, we just define "core_read" and "core_write" for our custom queries, it was that simple.



    My question is, how Magento knows when to insert on master DB (write) and when to get data from read replica (read)? I mean the object for both commands is same.










    share|improve this question


























      2












      2








      2








      I am using Magento 2.2.5 EE. I need to write some custom queries Select and Insert



      I know how to write custom query, its simple:



      Create new connection:



      $objectManager = MagentoFrameworkAppObjectManager::getInstance(); // Instance of object manager
      $resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
      $connection = $resource->getConnection();


      Apply select query through this:



      $tableName = $resource->getTableName('employee'); //gives table name with prefix
      //Select Data from table
      $sql = "Select * FROM " . $tableName;
      $result = $connection->fetchAll($sql);


      And Insert command using this:



      //Insert Data into table
      $sql = "Insert Into " . $tableName . " (emp_id, emp_name, emp_code, emp_salary) Values ('','XYZ','ABD20','50000')";
      $connection->query($sql);


      In magento 1.9, we just define "core_read" and "core_write" for our custom queries, it was that simple.



      My question is, how Magento knows when to insert on master DB (write) and when to get data from read replica (read)? I mean the object for both commands is same.










      share|improve this question
















      I am using Magento 2.2.5 EE. I need to write some custom queries Select and Insert



      I know how to write custom query, its simple:



      Create new connection:



      $objectManager = MagentoFrameworkAppObjectManager::getInstance(); // Instance of object manager
      $resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
      $connection = $resource->getConnection();


      Apply select query through this:



      $tableName = $resource->getTableName('employee'); //gives table name with prefix
      //Select Data from table
      $sql = "Select * FROM " . $tableName;
      $result = $connection->fetchAll($sql);


      And Insert command using this:



      //Insert Data into table
      $sql = "Insert Into " . $tableName . " (emp_id, emp_name, emp_code, emp_salary) Values ('','XYZ','ABD20','50000')";
      $connection->query($sql);


      In magento 1.9, we just define "core_read" and "core_write" for our custom queries, it was that simple.



      My question is, how Magento knows when to insert on master DB (write) and when to get data from read replica (read)? I mean the object for both commands is same.







      database magento-2.2.5 database-connection read-write






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 15 at 7:44







      Shoaib Munir

















      asked Feb 25 at 6:09









      Shoaib MunirShoaib Munir

      3,08151760




      3,08151760




















          1 Answer
          1






          active

          oldest

          votes


















          0














          First you should update your question so that one can find that you are talking about multiple db configuration.



          You can't use direct queries for this type of configuration. As it is stated in documentation.Split database performance solution (Magento Commerce only)




          Configuration options
          Because of the way the split database performance solution is designed, your custom code and installed components cannot do any of the following:




          - Write directly to the database (instead, you must use the Magento Commerce database interface)
          - Use JOINs that affect the sales or quote databases
          - Use foreign keys to tables in the checkout, sales, or main databases





          share|improve this answer























            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "479"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f263222%2fmagento-2-read-and-write-connection-for-custom-query%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            First you should update your question so that one can find that you are talking about multiple db configuration.



            You can't use direct queries for this type of configuration. As it is stated in documentation.Split database performance solution (Magento Commerce only)




            Configuration options
            Because of the way the split database performance solution is designed, your custom code and installed components cannot do any of the following:




            - Write directly to the database (instead, you must use the Magento Commerce database interface)
            - Use JOINs that affect the sales or quote databases
            - Use foreign keys to tables in the checkout, sales, or main databases





            share|improve this answer



























              0














              First you should update your question so that one can find that you are talking about multiple db configuration.



              You can't use direct queries for this type of configuration. As it is stated in documentation.Split database performance solution (Magento Commerce only)




              Configuration options
              Because of the way the split database performance solution is designed, your custom code and installed components cannot do any of the following:




              - Write directly to the database (instead, you must use the Magento Commerce database interface)
              - Use JOINs that affect the sales or quote databases
              - Use foreign keys to tables in the checkout, sales, or main databases





              share|improve this answer

























                0












                0








                0







                First you should update your question so that one can find that you are talking about multiple db configuration.



                You can't use direct queries for this type of configuration. As it is stated in documentation.Split database performance solution (Magento Commerce only)




                Configuration options
                Because of the way the split database performance solution is designed, your custom code and installed components cannot do any of the following:




                - Write directly to the database (instead, you must use the Magento Commerce database interface)
                - Use JOINs that affect the sales or quote databases
                - Use foreign keys to tables in the checkout, sales, or main databases





                share|improve this answer













                First you should update your question so that one can find that you are talking about multiple db configuration.



                You can't use direct queries for this type of configuration. As it is stated in documentation.Split database performance solution (Magento Commerce only)




                Configuration options
                Because of the way the split database performance solution is designed, your custom code and installed components cannot do any of the following:




                - Write directly to the database (instead, you must use the Magento Commerce database interface)
                - Use JOINs that affect the sales or quote databases
                - Use foreign keys to tables in the checkout, sales, or main databases






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 26 at 14:32









                Knight017Knight017

                387212




                387212



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f263222%2fmagento-2-read-and-write-connection-for-custom-query%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                    Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                    Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?