Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento - Fatal error: Class name must be a valid object or a string

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?

like image 912
Jason Millward Avatar asked Nov 14 '12 10:11

Jason Millward


1 Answers

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.

like image 68
Ricardo Martins Avatar answered Oct 05 '22 22:10

Ricardo Martins