6

I'm having a problem with a Magento installation that I hope someone can help me with.

I suddenly started getting the following error message when I accessed the site:

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

The function that this refers to is:

/**
  * Get connection type instance
  *
  * Creates new if doesn't exist
  *
  * @param string $type
  * @return Mage_Core_Model_Resource_Type_Abstract
  */
public function getConnectionTypeInstance($type)
{
    if (!isset($this->_connectionTypes[$type])) {
        $config = Mage::getConfig()->getResourceTypeConfig($type);
        $typeClass = $config->getClassName();
        $this->_connectionTypes[$type] = new $typeClass();
    }
    return $this->_connectionTypes[$type];
}

This is line 215:

$this->_connectionTypes[$type] = new $typeClass();

I've searched for someone with a similar issue but not had any luck so i'm stuck and really need to get this resolved

Can anyone help?

6
  • 1
    where are you getting this error? can you post a full stack trace? Commented Nov 14, 2012 at 11:11
  • @Tim how would I be able to get the full stack trace? The website is currently unavailable as all pages post this error Commented Nov 14, 2012 at 11:44
  • Enable logging (if disabled) and then check your var/log dir. Commented Nov 14, 2012 at 12:12
  • What changes have you made to the site or code recently?
    – Gga
    Commented Nov 14, 2012 at 12:38
  • echo $typeClass; exit; and tell us what is echoed;
    – Jscti
    Commented Nov 14, 2012 at 20:39

1 Answer 1

9

I had the same problem here. Try to add

<type>pdo_mysql</type>

in your local.xml file inside the connection node. It should be something like this:

        <default_setup>
            <connection>
                <host><![CDATA[localhost]]></host>
                <username><![CDATA[your_user]]></username>
                <password><![CDATA[your_pass]]></password>
                <dbname><![CDATA[your_db]]></dbname>
                <initStatements><![CDATA[SET NAMES utf8]]></initStatements>
                <model><![CDATA[mysql4]]></model>
                <type><![CDATA[pdo_mysql]]></type>
                <pdoType><![CDATA[]]></pdoType>
                <active>1</active>
            </connection>
        </default_setup>

And also try to check if your editor added line breaks or blank spaces when auto-formating your xml configuration file. Sometimes the value for the type node (and other nodes) are placed in the line bellow, and it breaks the parse. So, make sure that there is no space or line breaks around the values in your xml file.

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.