• 0

كيف أُبرمج سكريبت لتغيير جدول على magento دون اللجوء إلى استعمال SQL؟

هل بإمكاني كتابة سكريبت يقوم بعمل Update على جدول أو جداول على Magento دون الإستعانة إلى SQL؟ في حال كان الجواب نعم، كيف يمكنني فعل ذلك؟

تمّ تعديل بواسطة Badraoui

انشر على الشّبكات الاجتماعية


رابط هذه المساهمة
  • 0

يمكنك استعمال هذه الخصائص داخل السكريبت:

  • Varien_Db_Ddl_Table هذا الكلاس لإنشاء جدول جديد على قاعدة البيانات.

مثال:

/* @var $this Mage_Core_Model_Resource_Setup */
$table = new Varien_Db_Ddl_Table();
$table->setName($this->getTable('module/table'));
$table->addColumn('id', Varien_Db_Ddl_Table::TYPE_INT, 10, 
                  array('unsigned' => true, 'primary' => true));

$table->addColumn('name', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255);
$table->addIndex('name', 'name');
$table->setOption('type', 'InnoDB');
$table->setOption('charset', 'utf8');

$this->getConnection()->createTable($table);

استعمل ()this->getConnection$ لربط الاتصال بقاعدة البيانات.

بعض الوظائف:

  • addColumn() إضافة حقل.
  • addConstraint()  إضافة Constraint.
  • addKey() إضافة مفتاح Key.
  • dropColumn() حذف حقل.
  • modifyColumn تغيير حقل.

جمعتها هنا كلّها:

addColumn() method adds new column to exiting table. It has such parameters:
$tableName - the table name that should be modified
$columnName- the name of the column, that should be added
$definition - definition of the column (INT(10), DECIMAL(12,4), etc)
addConstraint() method creates a new constraint foreign key. It has such parameters
$fkName - the foreing key name, should be unique per database, if you don't specify FK_ prefix, it will be added automaticaly
$tableName - the table name for adding a foreign key
$columnName - the column name that should be refered to another table, if you have complex foreign key, use comma to specify more than one column
$refTableName - the foreign table name, wich will be handled
$refColumnName - the column name(s) in the foreign table
$onDelete - action on row removing in the foreign table. Can be empty string (do nothing), cascade, set null. This field is optional, and if it is not specified, cascade value will be used.
$onUpdate action on row key updating in the foreign table. Can be empty string (do nothing), cascade, set null. This field is optional, and if it is not specified, cascade value will be used.
$purge - a flag for enabling cleaning of the rows after foreign key adding (e.g. remove the recodrs that are not referenced)
addKey() method is used for adding of indexes to a table. It has such parameters:
$tableName - the table name where the index should be added
$indexName - the index name
$fields - column name(s) used in the index
$indexType - type of the index. Possible values are: index, unique, primary, fulltext. This parameter is optional, so the default value is index
dropColumn() method is used for removing of columns from the existing table. It has such parameters:
$tableName - the table name that should be modified
$columnName- the name of the column, that should removed
dropForeignKey() method is used for removing of foreing keys. It has such parameters:
$tableName - the table name for removing a foreign key
$fkName - the foreing key name
dropKey() method is used for removing of the table indexes. It has such parameters:
$tableName - the table name where the index should be removed
$keyName - the index name
modifyColumn method is used to modify existing column in the table. It has such parameters:
$tableName - the table name that should be modified
$columnName- the name of the column, that should be renamed
$definition - a new definition of the column (INT(10), DECIMAL(12,4), etc)
changeColumn method is used to modify and rename existing column in the table. It has such parameters:
$tableName - the table name that should be modified
$oldColumnName- the old name of the column, that should be renamed and modified
$newColumnName- a new name of the column
$definition - a new definition of the column (INT(10), DECIMAL(12,4), etc)
changeTableEngine method is used to change table engine, from MyISAM to InnoDB for instance. It has such parameters:
$tableName - the table name
$engine - new engine name (MEMORY, MyISAM, InnoDB, etc)

انشر على الشّبكات الاجتماعية


رابط هذه المساهمة

يجب أن تكون عضوًا لدينا لتتمكّن من التعليق

انشاء حساب جديد

يستغرق التسجيل بضع ثوان فقط


سجّل حسابًا جديدًا

تسجيل الدخول

تملك حسابا مسجّلا بالفعل؟


سجّل دخولك الآن