Magento – Magento Read & Write Connection Close Manually Needed

databasemagento-1.9

In case of customisation we need to initiate read and write connection in our .phtml file.

Should we manually close these connection at the end of file? or Magento self handles it?

In my case I have several time called read connections in my templates now I am feeling there must be any other solutions to handle this.

If I use multiple time Read Connection, would it may load up my database or server?

Somewhere I found it to be used.

Read Connection

$db = Mage::getSingleton('core/resource')->getConnection('core_read');

You can close the connection with this:

$db->closeConnection();

And then re-open it with this

$db->getConnection();

Should I do this for handling multiple and concurrent connections?

Let me know if any suggestion.

Best Answer

No, you dont have to close the connection .

There should be no read and write calls in .phtml file or template files , it is not best practice in MVC or Magento. You should use model for that .

Mage::getSingleton('core/resource')->getConnection('core_wri‌​te'); gets an already open connection. If you close it, other code will fail to reuse that connection

Related Topic