2

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.

6

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:

    <resources>
        <default_setup>
            <!-- your default mysql setup here -->
        </default_setup>
        <mssql_setup>
            <connection>
                <host><![CDATA[localhost]]></host>
                <username><![CDATA[dbuser]]></username>
                <password><![CDATA[dbpassword]]></password>
                <dbname><![CDATA[dbname]]></dbname>
            </connection>
        </mssql_setup>
    </resources>

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, privacy policy and cookie policy

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