gpt4 book ai didi

php - 从magento安装中的php文件运行自定义sql

转载 作者:行者123 更新时间:2023-11-29 08:08:23 25 4
gpt4 key购买 nike

我对 magento 很陌生,正在尝试运行自定义 sql 查询。但它没有运行。我包含了所需的所有法师文件,但它给出了错误 fatal error :不在对象上下文中使用 $this

我的查询文件内容

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();

最佳答案

//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();

关于php - 从magento安装中的php文件运行自定义sql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22249721/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com