اذهب إلى المحتوى
  • 0

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

Badraoui

السؤال

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

تم التعديل في بواسطة Badraoui
رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 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)
رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...