Friday 4 December 2015

How to Create a custom Database connection in Magento?

Create a connectdb.php file in your root folder. And paste the following code. Now 

you are able to access Data base on your file.




1. require_once ("app/Mage.php");

2. $app = Mage::app('default');

3. $config  = Mage::getConfig()->getResourceConnectionConfig("default_setup"); 

4. $dbinfo = array("host" => $config->host, "user" => $config->username,"pass" => $config->password, "dbname" => $config->dbname); 

5. $hostname = $dbinfo["host"];

6. $user = $dbinfo["user"];

7. $password = $dbinfo["pass"];

8. $dbname = $dbinfo["dbname"];

9. $con = mysql_select_db($dbname,mysql_connect($hostname,$user,$password));





4 comments:

  1. Really good to know about custom database, and its very informative. Thanks for these kind of posts, and keep updating.
    buy basra pearl online

    ReplyDelete
  2. Very nice blog and pretty well maintained. Keep it up and thanks for the post, keep updated.
    omega 3 fatty acids capsules

    ReplyDelete
  3. Really good to know about the custom database in magento, thanks for it.
    colon cancer surgery in india

    ReplyDelete