继续Drupal分享精神 QQ群:107748121 站长QQ:2275288328 skype: hellodrupal【drupal交流+drupal 建站+theme制作】
登录 注册

Drupal 数据写入数据库,Drupal hook_insert API应用

前面已经把输入数据的form做好了。你点击添加数据按钮是没有反应,
这就要用到hook_insert了. 这里是 http://api.drupal.org/api/function/hook_insert 关于hook_insert 的主要说明。
他下面还提供了一个例子:

<?php
function hook_insert($node) {
 
db_query("INSERT INTO {mytable} (nid, extra)
    VALUES (%d, '%s')"
, $node->nid, $node->extra);
}
?>

应用我写的模块那就是
function product_insert($node) {
db_query("INSERT INTO {product} (vid,nid,origin,engname,laname,anothername) VALUES (%d, %d, '%s', '%s', '%s', '%s')",
$node->vid, $node->nid, $node->origin, $node->engname, $node->laname, $node->anothername);

}

把数据写入product数据表里面。直接用,开发起来还是真的很简单,而且开发的速度快。不要自己来数据库录入的一些代码了。

评论

好太好啦

好太好啦

发表新评论

此内容将保密,不会被其他人看见。
  • 自动将网址与电子邮件地址转变为链接。
  • 自动断行和分段。
  • You can use BBCode tags in the text.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

更多关於格式化选项的信息

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.