I need to make connection in magento say a php file where i can make connection to MS SQL Server. can anyone please let me know how can i do this.

1 Answer 1


As Magento is heavily tied to MySQL you will need to use plain PHP or try it with the Zend Framework DB Adapter: Check out the mssql_connect function on php.net and Zend_Db_Adapter.

Also you need to make sure the needed MSSQL extension is enabled in your php.ini file, for example extension=php_mssql.dll

To store the username, password and host I suggest you use the same way in app/etc/local.xml just as Magento does it. You can then afterwards access the data in your PHP file.

app/etc/local.xml example:

            <!-- your default mysql setup here -->

access the data from local.xml to use in your PHP script:

$host = (string)$config->global->resources->mssql_setup->connection->host;
$username = (string)$config->global->resources->mssql_setup->connection->username,
$password = (string)$config->global->resources->mssql_setup->connection->password;
$dbname = (string)$config->global->resources->mssql_setup->connection->dbname;

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.