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?
-
Your question is not very clear. You have to give more details. Else I would answer, of course you can include external PHP file :-)Alexandre– Alexandre2012-03-13 15:54:47 +00:00Commented 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...Prat– Prat2012-03-13 16:23:18 +00:00Commented Mar 13, 2012 at 16:23
Add a comment
|
1 Answer
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.
3 Comments
Prat
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?
Ben Lessani
Just put the class into a custom module, as a model/helper.
Prat
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.