Posted by Steve McKenzie (not verified) on June 29, 2006 at 9:55pm
<?php /** * test.install <em>/
function test_install() { switch ($GLOBALS['db_type']) { case 'mysql': case 'mysqli': db_query("CREATE TABLE {test} ( nid int(11) NOT NULL, new_field varchar(250) NOT NULL, timestamp timestamp NOT NULL default CURRENT_TIMESTAMP ) TYPE=MyISAM /</em>!40100 DEFAULT CHARACTER SET utf8 */;" ); break; }
drupal_set_message(t('test module was successfully installed.')); } ?>
<?php /<strong> * test module */
/</strong> * Implementation of hook_help() */ function test_help($section) { switch ($section) { case 'admin/modules#description': return t('test module.'); } }
foreach ($nodes as $node_type) { if ($node_type = $node->type) { switch ($op) { case 'load': $result = db_query("SELECT new_field FROM {test} WHERE nid = %d", $node->nid); while ($row = db_fetch_object($result)) { $node->new_field = $row->new_field; } break; case 'save': case 'update': if (db_num_rows(db_query("SELECT nid FROM {test} WHERE nid = %d", $node->nid)) > 0) { db_query("UPDATE {test} SET new_field = '%s' WHERE nid = %d", $node->new_field, $node->nid); } else { db_query("INSERT INTO {test} (nid, new_field) VALUES (%d, '%s')", $node->nid, $node->new_field); } break; } } } } ?>
Comments
backup shell
backup shell script
http://drupal.org/node/59369
devel module
http://drupal.org/project/devel
database administration
http://drupal.org/project/dba
--
dave hansen-lange
--
Dave Hansen-Lange
Director of Technical Strategy, Advomatic.com
Pronouns: he/him/his
Forms API Quickstart Guide
Here is the forms quick start guide.
http://drupal.org/node/36050
http://www.sticksallison.com
Forms API Quickstart Guide
Here is the forms quick start guide.
http://drupal.org/node/36050
http://www.sticksallison.com
test module
<?php
/**
* test.install
<em>/
function test_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {test} (
nid int(11) NOT NULL,
new_field varchar(250) NOT NULL,
timestamp timestamp NOT NULL default CURRENT_TIMESTAMP
) TYPE=MyISAM /</em>!40100 DEFAULT CHARACTER SET utf8 */;"
);
break;
}
drupal_set_message(t('test module was successfully installed.'));
}
?>
<?php
/<strong>
* test module
*/
/</strong>
* Implementation of hook_help()
*/
function test_help($section) {
switch ($section) {
case 'admin/modules#description':
return t('test module.');
}
}
function test_settings() {
$form['field_set'] = array('#type' => 'fieldset',
'#title' => t('field content'),
'#collapsible' => true,
'#collapsed' => true
);
$form['field_set']['test_node_types'] = array('#type' => 'checkboxes',
'#title' => t('Available Node Types'),
'#default_value' => variable_get('test_node_types', node_get_types()),
'#options' => node_get_types()
);
return $form;
}
function test_form_alter($form_id, &$form) {
$nodes = variable_get('test_node_types', node_get_types());
foreach($nodes as $node_type) {
if ($form_id == $node_type .'_node_form') {
$node = node_load(array('nid' => arg(1)));
$form['new_field'] = array('#type' => 'textfield',
'#title' => t('New Field Title'),
'#default_value' => $node->new_field
);
}
}
}
function test_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
$nodes = variable_get('test_node_types', node_get_types());
foreach ($nodes as $node_type) {
if ($node_type = $node->type) {
switch ($op) {
case 'load':
$result = db_query("SELECT new_field FROM {test} WHERE nid = %d", $node->nid);
while ($row = db_fetch_object($result)) {
$node->new_field = $row->new_field;
}
break;
case 'save': case 'update':
if (db_num_rows(db_query("SELECT nid FROM {test} WHERE nid = %d", $node->nid)) > 0) {
db_query("UPDATE {test} SET new_field = '%s' WHERE nid = %d", $node->new_field, $node->nid);
} else {
db_query("INSERT INTO {test} (nid, new_field) VALUES (%d, '%s')", $node->nid, $node->new_field);
}
break;
}
}
}
}
?>
<!-- node.tpl.php -->
<div class="node<?php if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">
<?php if ($picture) {
print $picture;
}?>
<?php if ($page == 0) { ?><h2 class="title"><a href="<?php print $node_url?>"><?php print $title?></a></h2><?php }; ?>
<span class="submitted"><?php print $submitted?></span>
<span class="taxonomy"><?php print $terms?></span>
<div class="content"><?php print $content?></div>
<?php if ($node->new_field) { ?><div class="new_field"><?php print $node->new_field; ?></div><?php } ?>
<?php if ($links) { ?><div class="links">» <?php print $links?></div><?php }; ?>
</div>
uninstall the test module
delete from cache;
delete from system where name = 'test'