1

For my custom module I create a database table with the magento sql setups script. The problem is that if the magento installation has a prefix on the database it doesn't add the prefix. So the table is created but without the needed prefix.

Anybody knows how I can add this to my script?

asked Jul 24, 2014 at 9:20
1
  • please add your script to the question. Commented Jul 24, 2014 at 9:23

3 Answers 3

1

Use $this->getTable('yourmodule_table') in your sql script. The reference yourmodule_table should match what you have defined as a table in your config.xml.

answered Jul 24, 2014 at 9:40
1

You tried this?

$prefix = Mage::getConfig()->getTablePrefix();
echo $prefix;

While creating table in script file add $prefix to the table name.

Hope this will help you:)

answered Jul 24, 2014 at 10:56
1

suppose if your module is yourmodule and the table name is yourtablename, so in the app/code/local/yourcompmay/yourmodule/etc/config.xml file of this module, the resource entity tag will look like:

 <entities>
 <yourtable1> <!-- this is the reference of the table -->
 <table>yourtablename</table> <!--enter the actual table name within these table tags-->
 </yourtable1>
 </entities>

now you can call the table by reference by using the following code in setup files:

$this->getTable('module / table reference');

if I use above exampled values, it will become $this->getTable('yourmodule/yourtable1');, this will return the table name (with prefix if any).

answered Jul 24, 2014 at 10:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.