我是菜鸟,我只是写出个人的想法,看过了,生成的修改删除数据库的SQL语句好像没什么用处吧,
说错了,不要怪啊:)

解决方案 »

  1.   

    修改数据库的SQL语句适合从表单获得提交的数据,然后更新数据库
      

  2.   

    不错啊,hehe,我以前也自己写过一个这种的程序,不过当时是用php写的,本来想用js的,后来觉得js麻烦,没得用 php熟悉,heeh。有用啊。
      

  3.   

    不过,我个人的建议:你把里面涉及到的SQL语句都改成大写的,这样比较符合规范些,
      

  4.   

    我也对这个域名感兴趣,.name怎么申请的?
      

  5.   

    谢谢 wyx726(海风习习) 
    .name域名在万网就可以申请,80元/年
      

  6.   

    没有这么麻烦吧,写成这样不是更好吗?
    $sql = "Insert into riverking(a,b,c,d) values('$a','$b','$c','$d')";
    我都是这么写的没问题啊。
    请高手指点
      

  7.   

    不错哦,不过个人喜欢用把常用sql语句写成类,用到的时候只要往函数里面塞参数就行!呵呵……
      

  8.   

    看到楼主的东西,感觉和我的业务逻辑的基类有点类似,顺便贴下,
    <?php
    //====================================================
    // FileName:IBLogic.php
    // Summary: 基本数据操作模型,实现添加,删除,修改等
    //  使用时应注意表中自增字段名应为id
    // Author: ice_berg16(寻梦的稻草人)
    // LastModifed:2004-11-17 
    // copyright (c)2004 [email protected]
    // http://www.icebergweb.com
    //====================================================class IBLogic
    {
    var $DB; //数据访问层 var $tblName; //表的名称 var $fieldList; //字段名数组 //==========================================
    // 函数: baseLogic( $DB )
    // 功能: 构造函数
    // 参数: $DB mysql对象
    //==========================================
    function IBLogic( $DB ) 
    {
    $this->DB = $DB;
    }
    //==========================================
    // 函数: add($postList)
    // 功能: 添加
    // 参数: $postList 提交的变量列表
    // 返回: 刚插入的自增ID
    //==========================================
    function add( $postList )
    {
    $sql = "INSERT INTO {$this->tblName} VALUES('',";
    $value = "";  foreach ( $this->fieldList as $v ) 
    {
    if ( isset( $postList[$v] ) )
    {
    if ( !get_magic_quotes_gpc() )
    $value .= "'" . addslashes( $postList[$v] ) . "',";
    else
    $value .= "'" . $postList[$v] . "',";
    }
    else
    $value .= "'',";
    } //去掉最后一个逗号
    $value = rtrim( $value, "," );
    $sql .= $value . ")"; //echo $sql;
    $this->DB->query( $sql ); return $this->DB->insertID();
    }
    //==========================================
    // 函数: update( $postList )
    // 功能: 修改表数据
    // 参数: $postList 提交的变量列表
    //==========================================
    function update( $postList ) 
    {
    $sql = "UPDATE {$this->tblName} SET ";
    $value = "";  foreach ( $this->fieldList as $v ) 
    {
    if (isset( $postList[$v] ) )
    {
    if ( !get_magic_quotes_gpc() )
    $value .= $v . " = '" . addslashes( $postList[$v] ) . "',";
    else
    $value .= $v . " = '" . $postList[$v] . "',";
    }
    } //去掉最后一个逗号
    $value = rtrim( $value, "," );
    $sql .= $value . " WHERE id = '" . $postList['id'] . "'"; //echo $sql;exit();
    if ( $this->DB->query( $sql ) ) 
    {
    return true;
    }
    else 
    {
    return false;
    } }
    //==========================================
    // 函数: delete( $id )
    // 功能: 删除
    // 参数: $id 编号或ID列表数组
    // 返回: 0 失败 成功为删除的记录数
    //==========================================
    function delete( $id )
    {
    if( is_array( $id ) ) 
    {
    $tmp = "IN (" . join(",", $id) . ")";
    }
    else
    {
    $tmp = "= $id";
    } $sql = "DELETE FROM {$this->tblName} WHERE id " . $tmp ; $this->DB->query($sql); return $this->DB->affectedRows();
    }
    }?>看到楼主的东西发现我这个类有一个地方需要改进,就是主键应该允许自定义,
    所在业务逻辑类都继承这个基类,增加,删除,修改的部分只是调用基类方法即可。
    如一个产品操作类
      

  9.   

    <?php
    //====================================================
    // FileName:product.php
    // Summary: 产品操作类
    // Author: ice_berg16(寻梦的稻草人)
    // LastModifed:2004-12-13
    // copyright (c)2004 [email protected]
    // http://www.icebergweb.com
    //====================================================//包含基类文件
    require_once( dirname( __FILE__ ) . "/IBLogic.php" );class product extends IBLogic
    {
    /* //数据库字段描述
    var $id; //产品ID
    var $name; //产品名称
    var $description; //产品描述
    var $content; //内容
    var $catPath; //分类路径
    var $imgName; //产品的缩略图路径
    */ /* 函数 product( $DB )
    ** 功能 构造函数
    ** 参数 $DB mysql类
    */
    function product( $DB )
    {
    //父类的构造函数
    parent::IBLogic( $DB ); //产品表名及产品分类表名
    $this->tblName = IB_PREFIX . "product";
    $this->catTbl  = IB_PREFIX . "pro_cat";
    $this->pdTbl   = IB_PREFIX . "producer";
    $this->fieldList = array( "name", "description", "content", "catPath", "producerID", "imgName" );
    } /* 函数 addProduct( $postList )
    ** 功能 添加产品
    ** 参数 $$postList 字段和值的关联数组
    */
    function addProduct( $postList )
    {
    return $this->add( $postList );
    } /* 函数 editProduct( $postList )
    ** 功能 修改产品
    ** 参数 $postList 字段和值的关联数组
    */
    function editProduct( $postList )
    {
    return $this->update( $postList );
    } /* 函数 delProduct( $id )
    ** 功能 删除产品/支持多条
    ** 参数 $id 产品ID或ID列表数组
    */
    function delProduct( $id )
    {
    return $this->delete( $id );
    }}?>