没有问题,感觉dede官方做事情不讲究效率

解决方案 »

  1.   

    还有就是他们的数据结构设计的一点也不合理。
    一个网站所有的该当都在一个数据库当中,
    怪不得数据量大的时候慢呢
    请看:http://www.php-cms.cn/2008.html
      

  2.   

    dede的代码我也看过,确实有很多地方很乱。不过oop并不是唯一的方式。我看很多国内的开源程序很多都是这样写代码的。只有国外的那些著名开源程序整个架构比较好,比较严谨。
      

  3.   

    <?php
    define('C_P','../../');
    require_once(C_P.'inc/checkData/chkUser.php');require_once(C_P.'class/DataBase/recordSet.php');
    require_once(C_P.'inc/dbConfig.php');
    require_once(C_P.'inc/webConfig.php');$recordSet=new recordSet;
    $recordSet->mysqlConnect(
    $safeset['sqlServer'],
    $safeset['sqlRoot'],
    $safeset['sqlPW'],
    $safeset['sqlData'],
    $pconnect = 0
    );
    $recordSet->db_pro=$safeset['sqlPro'];$table=$recordSet->db_pro.'article'; //文章存放的表
    $classTable=$recordSet->db_pro.'class'; //文章栏目存放的表
    $imgTable=$recordSet->db_pro.'images'; //图片等附件存放的表$recordSet->fieldString=$recordSet->listFields($table); //用这个属性传递数据表各字段组成的字符串
    $key=explode(',',$recordSet->fieldString);
    $count=count($key);//给要插入数据表的数组元素赋值
    for($i=0;$i<$count;$i++)
    {
    if(isset($_POST[$key[$i]])&&$_POST[$key[$i]]!='')
    $post=$recordSet->checkPostAndGet($_POST[$key[$i]]);
    else
    $post=0;
    $arr[$key[$i]]=$post;
    }//获得发布者的信息
    $arr['authorid']=$_COOKIE['authorid'];
    $arr['authorname']=$_COOKIE['authorname'];//调整部分元素的值
    //*调用数据表中的值填充数组中为0的元素
    $keyword=array('id','authorid');
    if($arr['id']!=0)
    {
    $arr=$recordSet->getUpdateFieldDiff($table,$arr,$keyword);//用数据库记录调整数组的元素的值
    if($arr['tuijian']>=2)
    {
    echo "<script language=javascript>
    parent.retmsg1('<br/><font color=red>该文章已经在首页发布,不允许更改!</font>');
    </script>";
    exit;
    }
    }//通过表单和系统默认设定来调整数组元素的值
    $arr['title']=$recordSet->checkPostAndGet($_POST['blog_title']);
    $arr['content']=$recordSet->checkPostAndGet($_POST['blog_body']);
    $arr['zhuangtai']=1;$arr['range']=substr($arr['imglinkid'],-5);
    require_once(C_P.'func/getNowTime.php');
    if($arr['id']==0)
    {
    $arr['edittime']=getNowTime($config['time'],$config['defaulttime']);
    $arr['addtime']=getNowTime($config['time'],$config['defaulttime']);
    }else{
    $arr['edittime']=getNowTime($config['time'],$config['defaulttime']);
    }//获得当前栏目的上级栏目的ID
    $query="select upid from ".$classTable." where id='".$arr['b']."'";
    $row=$recordSet->mysqlGetOneResult($query);
    $arr['a']=$row['upid'];
    //确定数据表操作方式(必须放在附件上传之钱,否则imglinkid将不能得到最新的数据)//图片路径替换$query="select img,filepath,addtime from ".$imgTable." 
    where imglinkid='".$arr['imglinkid']."'";
    $result=$recordSet->mysqlQuery($query,$method='U_B') ;
    while($row= $recordSet->mysqlFetchArray($result, $result_type = MYSQL_ASSOC) )
    {
    if($row['filepath']!='0')
    {
    $oldPath[]=$row['filepath'];
    $newPath[]=$config['bbsurl'].'/images/uploads/'.subpath($row['addtime']).'/'.$row['img']; //注意图片的路径
    }
    }
    if(!isset($oldPath))
    $oldPath='';
    if(!isset($newPath))
    $newPath='';$arr['content']=$recordSet->checkPostAndGet(str_replace($oldPath,$newPath,$arr['content']));//附件上传
    if($_FILES['img']['name']!='')
    {
    require_once(C_P.'inc/uploadConfig.php');
    require_once(C_P.'inc/webConfig.php');
    require_once(C_P.'class/Pic/upload.php');

    $uploadFile=new uploadFile;

    $uploadFile->path=C_P;
    $uploadFile->sorFile=$_FILES['img'];
    $uploadFile->uploadSet=$upload;
    $uploadFile->nowTime=$arr['addtime'];

    //水印图片的地址
    $waterimg=C_P."images/uploads/water.gif";
    $newName=$uploadFile->upload($waterimg);

    $recordSet->fieldString=$recordSet->listFields($imgTable); //用这个属性传递数据表各字段组成的字符串
    $key=explode(',',$recordSet->fieldString);
    $count=count($key);

    //给要插入数据表的数组元素赋值
    for($i=0;$i<$count;$i++)
    {
    if(isset($_POST[$key[$i]]))
    $post=$recordSet->checkPostAndGet($_POST[$key[$i]]);
    else
    $post=0;
    $arrimg[$key[$i]]=$post;
    }
    //把图片的信息放入数据库
    if(isset($_POST['detail']))
    $arrimg['title']=$recordSet->checkPostAndGet($_POST['detail']);
    else
    $arrimg['title']=$arr['title'];

    $arrimg['imglinkid']=$arr['imglinkid'];
    $arrimg['img']=$newName;
    $arrimg['addtime']=$uploadFile->nowTime;
    $action='insert'; //通过这种途径上传的图片都只是新插入。没有修改 if(strlen($newName)>5)
    {
    $recordSet->getRecordSet($imgTable,$action,$arrimg,$keyword); //插入数据库了。
    $msg='<br/><font color=green>附件上传成功!<br/>';
    }else{
    $msg='<br/><font color=red>附件上传失败!<br/>';
    }
    }if($_FILES['img']['name']!=''&&strlen($newName)>5)
    {
    if($_POST['detail']!='')
    $detail=$recordSet->checkPostAndGet($_POST['detail']);
    else
    $detail='附件';
    $string=$uploadFile->makeTypeCode($arrimg['img'],$detail,$arr['addtime'],'../');
    $arr['content']=$string.$arr['content'];
    }
    //把文章部分写如数据表
    $recordSet->fieldString=$recordSet->listFields($table); //用这个属性传递数据表各字段组成的字符串
    if($arr['id']==0)
    $action='insert';
    else{
    $action='update';
    }
    $key=array('id','authorid');//where 语句后面的条件字段组成的数组。以and连接,多用户系统需要$recordSet->getRecordSet($table,$action,$arr,$keyword); //插入数据库了。
    if(isset($msg))
    $msg=$msg.'文章写入数据库成功!</font>';
    else
    $msg='<br/><font color=green>文章写入数据库成功!</font>';if($arr['id']==0)
    $insert=$recordSet->mysqlInsertId();
    else
    $insert=$arr['id'];echo "<script language=javascript>parent.retmsg1('".$msg."');</script>";
    echo "<script language=javascript>window.location.href='".C_P."html/article.php?id=".$insert."';</script>";
    exit;function subpath($time)
    {
    $path=date('Y',$time);
    $path=$path."/".date('Y-m',$time);
    $path=$path."/".date('Y-m-d',$time);
    return $path;
    }
    ?>这个是我的系统的代码风格
    包含了图片上传,图片记录入数据库
    文章记录入数据库
      

  4.   

    你这样写很好吗?
    到最后insert函数,还不是得构造原始的sql语句.
    且不知道,如果一个表有20个字段的话,你就要$arr["字段二十"]= "xx";
    没觉得你这样写高效在哪里! 
      

  5.   


    那应该怎样写比较好?我就是按照dede的那样插入
      

  6.   

    不要把简单的问题复杂化,写这段SQL语句要比你存在数组里效率高很多,而且也容易调试,还有其他问题吗?
      

  7.   

    写法是习惯问题,关键在于效率.PHPCMS里面也有这样的写法,我觉得很好,执行效率很高.