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;
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
add a comment |
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
add a comment |
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
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
database magento-2.2.5 database-connection read-write
edited May 15 at 7:44
Shoaib Munir
asked Feb 25 at 6:09
Shoaib MunirShoaib Munir
3,08151760
3,08151760
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Mar 26 at 14:32
Knight017Knight017
387212
387212
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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