我对magento很新,并尝试运行自定义SQL查询。但它没有跑步。我包含了所需的所有mage文件,它给出了错误Fatal error: Using $this when not in object context
。
我的查询文件内容
require_once 'app/Mage.php';
Mage::init();
$setup = Mage::getModel('eav/entity_setup', 'core_setup');
$installer = $this;
$table = $this->getConnection()
->newTable($this->getTable('campaigns/paramcampaign'))
->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'identity' => true,
'nullable' => false,
'primary' => true,
), 'Campaign ID')
->addColumn('campaignname', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
'nullable' => false,
), 'Campaign Name')
->addColumn('campaigndesc', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array(
'nullable' => false,
), 'Campaign Description ')
->addColumn('campaignnameprice', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
'nullable' => false,
), 'Campaign Goal Price')
->addColumn('campaignstartdate', Varien_Db_Ddl_Table::TYPE_DATETIME, 255, array(
'nullable' => false,
), 'Campaign Start date')
->addColumn('campaignenddate', Varien_Db_Ddl_Table::TYPE_DATETIME, 255, array(
'nullable' => false,
), 'Campaign End date')
->addColumn('campaignfbgoal', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'nullable' => false,
'unsigned' => true,
), 'Campaign Facebook Shares/Likes Goal')
->addColumn('campaignpinterestgoal', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'nullable' => false,
'unsigned' => true,
), 'Campaign Pinterest Shares Goal')
->addColumn('campaignamtdonate', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'nullable' => false,
'unsigned' => true,
), 'Campaign Percentage / Amount To Donate ')
->addColumn('campaigncheckpercent', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'nullable' => false,
), 'Is The Specified Amount is Percentage ? ')
->addColumn('campaigngoalrecv', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
), 'Campaign Goal Amount Achieved')
->addColumn('campaignfbgoalrecv', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'unsigned' => true,
), 'Campaign Facebook Shares/Likes Goal Achieved ')
->addColumn('campaignpingoalrecv', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'unsigned' => true,
), 'Campaign Pinterest Shares Achieved ')
->addColumn('url_key', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
), 'URL key')
->addColumn('status', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
), 'Status')
->addColumn('in_rss', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
), 'In RSS')
->addColumn('meta_title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
), 'Meta title')
->addColumn('meta_keywords', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array(
), 'Meta keywords')
->addColumn('meta_description', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array(
), 'Meta description')
->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
), 'Campaign Creation Time')
->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
), 'Campaign Modification Time')
->setComment('Campaign Table');
$this->getConnection()->createTable($table);
$table = $this->getConnection()
->newTable($this->getTable('campaigns/paramcampaign_store'))
->addColumn('paramcampaign_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
'nullable' => false,
'primary' => true,
), 'Campaign ID')
->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
'unsigned' => true,
'nullable' => false,
'primary' => true,
), 'Store ID')
->addIndex($this->getIdxName('campaigns/paramcampaign_store', array('store_id')), array('store_id'))
->addForeignKey($this->getFkName('campaigns/paramcampaign_store', 'paramcampaign_id', 'campaigns/paramcampaign', 'entity_id'), 'paramcampaign_id', $this->getTable('campaigns/paramcampaign'), 'entity_id', Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
->addForeignKey($this->getFkName('campaigns/paramcampaign_store', 'store_id', 'core/store', 'store_id'), 'store_id', $this->getTable('core/store'), 'store_id', Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
->setComment('Campaign To Store Linkage Table');
$this->getConnection()->createTable($table);
$table = $this->getConnection()
->newTable($this->getTable('campaigns/paramcampaign_product'))
->addColumn('rel_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'unsigned' => true,
'identity' => true,
'nullable' => false,
'primary' => true,
), 'Category ID')
->addColumn('paramcampaign_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'unsigned' => true,
'nullable' => false,
'default' => '0',
), 'Campaign ID')
->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'unsigned' => true,
'nullable' => false,
'default' => '0',
), 'Product ID')
->addColumn('position', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'nullable' => false,
'default' => '0',
), 'Position')
->addIndex($this->getIdxName('campaigns/paramcampaign_product', array('product_id')), array('product_id'))
->addForeignKey($this->getFkName('campaigns/paramcampaign_product', 'paramcampaign_id', 'campaigns/paramcampaign', 'entity_id'), 'paramcampaign_id', $this->getTable('campaigns/paramcampaign'), 'entity_id', Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
->addForeignKey($this->getFkName('campaigns/paramcampaign_product', 'product_id', 'catalog/product', 'entity_id'), 'product_id', $this->getTable('catalog/product'), 'entity_id', Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
->setComment('Campaign to Product Linkage Table');
$this->getConnection()->createTable($table);
$this->endSetup();
答案 0 :(得分:2)
//ini_set("display_errors",1);
require_once 'app/Mage.php';
Mage::init();
Mage::app("default");
$installer= Mage::getModel('eav/entity_setup', 'core_setup');
//$installer = $installer;
$installer->startSetup();
$table = $installer->getConnection('core/resource')
->newTable('tablename')
->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'identity' => true,
'nullable' => false,
'primary' => true,
), 'Campaign ID')
->addColumn('campaignname', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
'nullable' => false,
), 'Campaign Name')
->addColumn('campaigndesc', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array(
'nullable' => false,
), 'Campaign Description ')
->addColumn('campaignnameprice', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
'nullable' => false,
), 'Campaign Goal Price')
->addColumn('campaignstartdate', Varien_Db_Ddl_Table::TYPE_DATETIME, 255, array(
'nullable' => false,
), 'Campaign Start date')
->addColumn('campaignenddate', Varien_Db_Ddl_Table::TYPE_DATETIME, 255, array(
'nullable' => false,
), 'Campaign End date')
->addColumn('campaignfbgoal', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'nullable' => false,
'unsigned' => true,
), 'Campaign Facebook Shares/Likes Goal')
->addColumn('campaignpinterestgoal', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'nullable' => false,
'unsigned' => true,
), 'Campaign Pinterest Shares Goal')
->addColumn('campaignamtdonate', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'nullable' => false,
'unsigned' => true,
), 'Campaign Percentage / Amount To Donate ')
->addColumn('campaigncheckpercent', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'nullable' => false,
), 'Is The Specified Amount is Percentage ? ')
->addColumn('campaigngoalrecv', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
), 'Campaign Goal Amount Achieved')
->addColumn('campaignfbgoalrecv', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'unsigned' => true,
), 'Campaign Facebook Shares/Likes Goal Achieved ')
->addColumn('campaignpingoalrecv', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'unsigned' => true,
), 'Campaign Pinterest Shares Achieved ')
->addColumn('url_key', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
), 'URL key')
->addColumn('status', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
), 'Status')
->addColumn('in_rss', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
), 'In RSS')
->addColumn('meta_title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
), 'Meta title')
->addColumn('meta_keywords', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array(
), 'Meta keywords')
->addColumn('meta_description', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array(
), 'Meta description')
->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
), 'Campaign Creation Time')
->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
), 'Campaign Modification Time')
->setComment('Campaign Table');
$installer->getConnection()->createTable($table);
$installer->endSetup();