Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Error beginTransaction() on my mysql4 Model
 
FIANET_EUROPE
Sr. Member
 
Avatar
Total Posts:  143
Joined:  2008-06-27
 

Hello,

I’m currently working on a FIA-NET module for magento (a french anti-fraud system)
But I can’t progress since I don’t understand why i systematically get this error when I try to save my model in database :
Fatal error: Call to a member function beginTransaction() on a non-object in /var/www/magento/app/code/core/Mage/Core/Model/Resource/Abstract.php on line 57

I have created a class in Model/Fianet/Catproduct/Association.php
then I have created the associated Mysql4 Model in :
Model/Mysql4/Fianet/Catproduct/Association.php
Model/Mysql4/Fianet/Catproduct/Association/Collection.php

I also have created a page which contain a form in order to associate Magento’s categories to our product type.

But when I try to use my class in the page controller I get the error message :

$catproductModel Mage::getModel('fianet/fianet_catproduct_association');
$catproductModel->setId($catId)
->
setFianet_product_type($productId)
->
save();

Here is the related config.xml part :

<models>
            <
fianet>
                <class>
Mage_Fianet_Model</class>
                <
resourceModel>fianet_mysql4</resourceModel>
            </
fianet>
            <
fianet_mysql4>
                <class>
Mage_Fianet_Model_Mysql4</class>
                <
entities>
                    <
fianet_catproduct_association>
                        <
table>fianet_catproduct_association</table>
                    </
fianet_catproduct_association>
                </
entities>
            </
fianet_mysql4>
        </
models>

I joined the current module I have done, I someone can help me because i’m looking since 3 days for that.

File Attachments
Fianet.zip  (File Size: 18KB - Downloads: 89)
 
Magento Community Magento Community
Magento Community
Magento Community
 
Ron Peled
Jr. Member
 
Avatar
Total Posts:  18
Joined:  2008-08-24
Los Angeles
 

You may want to check you config.xml content:

Instead of what you have showed, you need to write:

<models>
            <
fianet>
                <class>
Mage_Fianet_Model</class>
                <
resourceModel>fianet_mysql4</resourceModel>
            </
fianet>
            <
fianet_mysql4>
                <class>
Mage_Fianet_Model_Mysql4</class>
                <
entities>
                    <
association>
                        <
table>fianet_catproduct_association</table>
                    </
association>
                </
entities>
            </
fianet_mysql4>
</
models>

also make sure you refer to the resource as ‘fianet/association’.

you may also have a bigger problem, is your company name Fianet? if so - the module should not really include any references to your company name but instead all the xml nodes should reference the module name. Which is also reflected in your class names, something like:
Fianet_Modulename_Model_Association

will be the class name for your association resource in the ‘Modulename’ module which is setup under your company ‘Fianet’.

hope this helps.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rohit85
Member
 
Total Posts:  32
Joined:  2008-12-16
 

Hi,

I fixed with this issue.

I have the same issue, i created my own module with admin section that was accessing data from my own table.

While i was accessing data base i was getting error \"Fatal error: Call to a member function beginTransaction() on a non-object in /var/www/magento/app/code/core/Mage/Core/Model/...\”

I seek and i found it was due to my Mysql4 class file name was in lowercase. I am talking about the file in modulename/model/Mysql4/

I corrected its first character to Uppercase and i got it working. My issue is solved.

Try this if any one have this problem.

Thank you

 
Magento Community Magento Community
Magento Community
Magento Community
 
vishal_2811
Jr. Member
 
Avatar
Total Posts:  20
Joined:  2011-04-17
 

Dear All,
I am new to magento. I am creating my own new module ("Invite" under “Mage") to interact with the databse table ("invite") to the users i invite on invite_a_friend.phtml page but it gives me the error Fatal error: Call to a member function beginTransaction() on a non-object in /backup/ons/projects/ShopBellaBag.pbodev.info/code/app/code/core/Mage/Core/Model/Abstract.php on line 301 downer . The code in files mentioned below.

==================================
code/app/etc/config.xml

....
<
models>
            <
varien>
                <class>
Varien</class>
            </
varien>
            <
core>
                <class>
Mage_Core_Model</class>
                <
resourceModel>core_mysql4</resourceModel>
            </
core>
            <
core_mysql4>
                <class>
Mage_Core_Model_Mysql4</class>
                <
entities>                    
            
[b]<invite><table>invite</table></invite>[/b]            
                    
<config_data><table>core_config_data</table></config_data>
                    <
website><table>core_website</table></website>
                    <
store><table>core_store</table></store>
                    <
resource><table>core_resource</table></resource>
                    <
cache><table>core_cache</table></cache>
                    <
cache_tag><table>core_cache_tag</table></cache_tag>
                    <
cache_option><table>core_cache_option</table></cache_option>
                </
entities>
            </
core_mysql4>
        </
models>
...

==================================
app/code/local/Mage/Invite/Model/Invite.php
<?php

class Mage_Invite_Model_Invite extends Mage_Core_Model_Abstract
{

    
public function _construct()
    
{
        parent
::_construct();
        
$this->_init('invite/invite');
    
}
}
?>

==================================
app/code/local/Mage/Invite/Model/Mysql4/Invite.php

<?php     
    
class Mage_Invite_Model_Mysql4_Invite extends Mage_Core_Model_Mysql4_Abstract
    {
        
public function _construct()
        
{
            $this
->_init('invite/invite''invite_id');
        
}
    }
?>

==================================
app/code/local/Mage/Invite/Model/Mysql4/Invite/Collection.php

<?php     
    
class Mage_Invite_Model_Mysql4_Invite_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
    {
        
public function _construct()
        
{
            parent
::_construct();
            
$this->_init('invite/invite');
        
}
    }
?>

Then i tried
==================================
code/app/design/frontend/default/default/template/page/invite_a_friend.phtml

<?php
$model 
Mage::getModel('invite/invite');
$model->setName('The three Tree')->save();
?>

<div>say hi</div>

It shows
Fatal error: Call to a member function beginTransaction() on a non-object in /backup/ons/projects/ShopBellaBag.pbodev.info/code/app/code/core/Mage/Core/Model/Abstract.php on line 301

Please help me. Thanks in advance.

 
Magento Community Magento Community
Magento Community
Magento Community
 
denispopov
Jr. Member
 
Total Posts:  1
Joined:  2010-08-16
 

You need to create model in your directory folders like this:
class <YourNamespace>_<YourModule>_Model_Mysql4_<YourModule> extends Mage_Core_Model_Mysql4_Abstract
{
public function _construct()
{
$this->_init(’<yourmodule>/<yourmodule>’, ‘<yourmodule>_id’);
}
}

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top