0

How to include external PHP file in Magento? Can we include this file in event-observer model's Observer.php file? How can we execute external PHP file in Magento?

2
  • Your question is not very clear. You have to give more details. Else I would answer, of course you can include external PHP file :-) Commented Mar 13, 2012 at 15:54
  • Hi Alexandre, I have created 1 php file that contains connection to mysql & oracle dbs & query which fetches & inserts data into these dbs. How can I use ths file so that once customer places order,this file should call & function in it get executed.so that placed order data get into my both databases. Anothr approach-If I got order-Id from event-observer method.then can I put that php file code in this Observer.php so that with the generated order-id, data can be fetched & inserted in Custom table? Or how Can I include/execute that PHP file from my event-observer model?? Or any other way... Commented Mar 13, 2012 at 16:23

1 Answer 1

1

Including another class can easily be achieved by just making an extension for the classes used. Then just use standard Magento class loading techniques to access them:

Mage::getModel('mynamespace/mymodule')->myFunction()
Mage::helper('mymodulefrontname')->myFunction()

It would also be worth considering creating the MySQL connection through Zend/Varien itself. Here is a starter function:

protected function _initiateDbConnection()
{
        $configs = array('model' => 'mysql4', 'active' => '1', 'host' => 'localhost', 'username' => '', 'password' => '', 'dbname' => '', 'charset' => 'utf8');         
        return Mage::getSingleton('core/resource')->createConnection('mymodule_read', 'pdo_mysql', $configs);
} 

Which will give you an Zend DB instance that you can execute query() etc. on.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi Sonassi, I have external PHP file sample.php conating classes mysql with function of connection for mysql, fetch data, insertion & class oracle with function of connection for Oracle. So how can I include this file in Observer.php or how can I call this file?
Just put the class into a custom module, as a model/helper.
HI Sonassi, Can u please provide me any sample code for the same for my better understanding. Or tell me steps to include external php file in magennto.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.