本文整理汇总了PHP中XMLDBTable::addIndex方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLDBTable::addIndex方法的具体用法?PHP XMLDBTable::addIndex怎么用?PHP XMLDBTable::addIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLDBTable
的用法示例。
在下文中一共展示了XMLDBTable::addIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getDbTables
private static function getDbTables()
{
$tables = array();
// globalmessages table
$table = new XMLDBTable('local_globalmessages');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('summary', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
$table->addFieldInfo('description', XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('created', XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('modified', XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('status', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 0);
$table->addFieldInfo('design', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$index = new XMLDBIndex('design');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('design'));
$table->addIndex($index);
$index = new XMLDBIndex('modified');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('modified'));
$table->addIndex($index);
$tables[] = $table;
// globalmessages_designs table
$table = new XMLDBTable('local_globalmessages_designs');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('height', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 400);
$table->addFieldInfo('width', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 400);
$table->addFieldInfo('bgcolor', XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null);
$table->addFieldInfo('bgimage', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
$table->addFieldInfo('bgimageposition', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
$table->addFieldInfo('bgimagerepeat', XMLDB_TYPE_CHAR, '50', null, null, null, null, null, null);
$table->addFieldInfo('bordersize', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 0);
$table->addFieldInfo('bordercolor', XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null);
$table->addFieldInfo('bordershape', XMLDB_TYPE_CHAR, '50', null, null, null, null, null, null);
$table->addFieldInfo('padding', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
$table->addFieldInfo('innerpadding', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$tables[] = $table;
// globalmessages_rules table
$table = new XMLDBTable('local_globalmessages_rules');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('construct', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('leftside', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('operator', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('rightside', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('message', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$index = new XMLDBIndex('message');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('message'));
$table->addIndex($index);
$tables[] = $table;
return $tables;
}
示例2: invoke
//.........这里部分代码省略.........
if (!$tableparam) {
/// No postaction here
$this->postaction = NULL;
/// Get list of tables
$dbtables = $db->MetaTables('TABLES');
$selecttables = array();
foreach ($dbtables as $dbtable) {
$dbtable = strtolower(str_replace($CFG->prefix, '', $dbtable));
$i = $structure->findTableInArray($dbtable);
if ($i === NULL) {
$selecttables[$dbtable] = $dbtable;
}
}
/// Get list of after tables
$aftertables = array();
if ($tables =& $structure->getTables()) {
foreach ($tables as $aftertable) {
$aftertables[$aftertable->getName()] = $aftertable->getName();
}
}
if (!$selecttables) {
$this->errormsg = 'No tables available to be retrofitted';
return false;
}
/// Now build the form
$o = '<form id="form" action="index.php" method="post">';
$o .= '<div>';
$o .= ' <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
$o .= ' <input type="hidden" name ="action" value="new_table_from_mysql" />';
$o .= ' <input type="hidden" name ="postaction" value="edit_table" />';
$o .= ' <table id="formelements" class="boxaligncenter" cellpadding="5">';
$o .= ' <tr><td><label for="table" accesskey="t">' . $this->str['createtable'] . ' </label>' . choose_from_menu($selecttables, 'table', '', 'choose', '', 0, true) . '<label for="after" accesskey="a">' . $this->str['aftertable'] . ' </label>' . choose_from_menu($aftertables, 'after', '', 'choose', '', 0, true) . '</td></tr>';
$o .= ' <tr><td colspan="2" align="center"><input type="submit" value="' . $this->str['create'] . '" /></td></tr>';
$o .= ' <tr><td colspan="2" align="center"><a href="index.php?action=edit_xml_file&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a></td></tr>';
$o .= ' </table>';
$o .= '</div></form>';
$this->output = $o;
/// If table, retrofit information and, if everything works,
/// go to the table edit action
} else {
/// Get some params (table is mandatory here)
$tableparam = required_param('table', PARAM_CLEAN);
$afterparam = required_param('after', PARAM_CLEAN);
/// Create one new XMLDBTable
$table = new XMLDBTable(strtolower(trim($tableparam)));
$table->setComment($table->getName() . ' table retrofitted from MySQL');
/// Get fields info from ADODb
if (!($dbfields = $db->MetaColumns($CFG->prefix . $tableparam))) {
///Try it without prefix if doesn't exist
$dbfields = $db->MetaColumns($tableparam);
}
if ($dbfields) {
foreach ($dbfields as $dbfield) {
/// Create new XMLDB field
$field = new XMLDBField(strtolower($dbfield->name));
/// Set field with info retrofitted
$field->setFromADOField($dbfield);
/// Add field to the table
$table->addField($field);
}
}
/// Get PK, UK and indexes info from ADODb
$dbindexes = $db->MetaIndexes($CFG->prefix . $tableparam, true);
if ($dbindexes) {
$lastkey = NULL;
//To temp store the last key processed
foreach ($dbindexes as $indexname => $dbindex) {
/// Add the indexname to the array
$dbindex['name'] = $indexname;
/// We are handling one XMLDBKey (primaries + uniques)
if ($dbindex['unique']) {
$key = new XMLDBKey(strtolower($dbindex['name']));
/// Set key with info retrofitted
$key->setFromADOKey($dbindex);
/// Set default comment to PKs
if ($key->getType() == XMLDB_KEY_PRIMARY) {
}
/// Add key to the table
$table->addKey($key);
/// We are handling one XMLDBIndex (non-uniques)
} else {
$index = new XMLDBIndex(strtolower($dbindex['name']));
/// Set index with info retrofitted
$index->setFromADOIndex($dbindex);
/// Add index to the table
$table->addIndex($index);
}
}
}
/// Finally, add the whole retroffited table to the structure
/// in the place specified
$structure->addTable($table, $afterparam);
}
/// Launch postaction if exists (leave this here!)
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
/// Return ok if arrived here
return $result;
}