I want to add a connection to our ERP database that uses MS-Server, but i can't figure out what I'm doing wrong.

I know how to connect to another MySQL DB, but for MSSQL?


            <!-- ??? -->
            <!-- ??? -->

If I try this to list all tables ...

$resource   = Mage::getSingleton('core/resource');
$connection = $resource->getConnection('erp_db');
$results    = $connection->fetchAll('SELECT * FROM sysobjects WHERE xtype="U"');

I get ...

Fatal error: Class name must be a valid object or a string in /app/code/core/Mage/Core/Model/Resource.php on line 225

I also read Using MS SQL with Magento 1.9, some say it's not supported, but from comments it seems to be possible ...

The PDO adapter exists in Zend_Db_Adapter_Pdo_Mssql, but how to correctly use it?


1 Answer 1


Try adding this to the local.xml file inside the config/global tag

<resource><!-- singular form. No 's' at the end -->
                <compatibleMode>1</compatibleMode><!-- Not sure of what this does or if it's even needed -->

Still it won't work probably because the class listed above in the class tag does not exist...
you can create one based on Mage_Core_Model_Resource_Type_Db_Pdo_Mysql and replace the value above with the class name you create.
What you need to change is the result of the method _getDbAdapterClassName.

You are getting that error because the method getResourceTypeConfig in the same class returns null. This method should return this->_xml->global->resource->connection->types->{$type}. That's why I added the node pdo_mssql inside connection types.

Note: This is not tested, I started from the error message you got and checked what could be missing.

  • Had no time to test it, just checked the classes/methods you've mentioned ... so what should be the return value of _getDbAdapterClassName? However, thank for your time :)
    – sv3n
    Commented Mar 28, 2018 at 21:00
  • Not sure. Probably the value of adapter from the xml. Zend_Db_Adapter_Pdo_Mssql. Not sure how this works.
    – Marius
    Commented Mar 29, 2018 at 6:23
  • great that you created new Html tagname : <Edit> , i will start using this in our project :) Commented Mar 29, 2018 at 10:39
  • Thanks for your effort @Marius. Still no time to test :( I'll come back as soon as i have time for.
    – sv3n
    Commented Mar 30, 2018 at 12:49

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.