无级分类算法的实现与其可用性

作者 : admin 于 2008年10月14日, 22:27:27
2008
10-14

根据动易ASP CMS的算法,简单实现了无级分类的算法,不过根据系统易用性原则,这种无级的分类很难在实际的CMS系统中应用,因此,这种算法在中小型信息管理系统中是不需要的,而大型的信息管理系统也要尽量避免分类深度过高而造成的系统效率问题。总结下来,这只能算自己连手的一个作品。

PHP缓存组件APC简介

作者 : admin 于 2008年10月03日, 10:55:15
2008
10-3

php是解释型语言,比起编译型语言,速度自然会慢.每种语言基本都是 1、源代码->编译成二进制机器码 2、编译成二进制机器码->执行 编译型语言(如c,java)在执行一次步骤1后,多次执行步骤2,而asp,php之类的解释型语言每次访问,都重复步骤1,2,故效率低下。

PHP官方提供了一个编译php为二进制码的工具,Zend,价格昂贵,今天讨论免费的APC。

APC组件下载地址:http://pecl4win.php.net/ext.php/php_apc.dll http://pecl.php.net/package/apc 根据自己的操作系统版本来下载安装。我这里使用的是windows系统,直接把php_apc.dll放在扩展文件路径里,在php.ini里增加extension=php_apc.dll,再查看phpinfo(),可看到apc安装成功的信息。具体配置信息在这里 http://cn2.php.net/manual/en/apc.configuration.php

其中的参数可以设定是否缓存php的编译文件,还有一些常用的限制。

除此之外,还有很多opcode缓存组件,如accelerator,xcache之类,详情可参见这里 http://en.wikipedia.org/wiki/Alternative_PHP_Cache#Alternative_PHP_Cache

Mysql数据库抽象层操作类

作者 : admin 于 2008年09月08日, 14:26:23
2008
09-8

DB.InterFace.php

  1. < ?php
  2. /*  DB.InterFace.php
  3.  *  DB
  4.  *  @link        http://www.sunboyu.cn
  5.  *  @package     OA
  6.  *  @version     V1.0
  7.  *
  8.  *  2008 08 28  sunboyu@gmail.com
  9.  *  Demo
  10.  */
  11. interface DateBaseConnect
  12. {
  13.     #数据库连接
  14.     public function Connect( $host , $user , $pass , $datebase );
  15. #使用数据库
  16. public function selectDateBase( $datebase );
  17. #执行一个查询
  18. public function Query( $sql );
  19. #取得一行
  20. public function fetchRow( $sql );
  21. #取得所有
  22. public function fetchAll( $sql );
  23. #取得影响行数
  24. public function affectedRow();
  25. #取得结果行数
  26. public function recordCount();
  27. #取得上次插入ID
  28. public function insertID();
  29. #释放资源
  30. public function close();
  31. }
  32. ?>

阅读全部 »

倒霉的ADODB,折腾死了

作者 : admin 于 2008年09月05日, 16:56:31
2008
09-5

突然发现ADODB_lite很多方法跟以前不一样了,变了好多,所以,一气之下决定放弃adodb,自己写个数据抽象层的类。

用别人的东西总是有很多的局限,如果去修改,工作量又很大。其实我们使用的也就是那么点功能,这样我们去完成自己的类工作量并不大,而且能根据自己的需求不断改进。

简单分页程序,adodb+smarty

作者 : admin 于 2008年08月31日, 17:56:16
2008
08-31

分页类

  1. <?php
  2. /*  Page.Class.php
  3.  *  Page
  4.  *  @link        http://www.sunboyu.cn
  5.  *  @package     OA
  6.  *  @version     V1.0
  7.  *
  8.  *  2008 08 28  sunboyu@gmail.com
  9.  *  Demo
  10. $page = new Page( 1 , 'v_user' , '*' , '' );
  11. $rs = $page->__getlist();
  12. $smarty->assign("page",$page->__getpagelist());
  13.  */
  14.  class Page
  15.  {
  16. public $count;      #结果总数
  17. public $page;       #当前页
  18. public $pagesize;   #每页结果数
  19. public $pagecount;  #翻页数
  20. public $baseurl;    #url
  21. public $result;     #结果数组集
  22. public $pagelist;   #每翻页数
  23. public $db;         #数据库连接
  24. public $table;      #要查询的表
  25. public $fileds;     #要返回的字段
  26. public $where;      #where条件
  27.  
  28. #构造函数,初始化变量
  29. function __construct( $page , $table , $fields = '*' , $where = false , $baseurl = false )
  30. {
  31.      global $_CFG;
  32. $this->db        = GetDB();
  33. $this->count     = $count;
  34. $this->table     = $table;
  35. $this->page      = isset($page) ? intval($_GET['page']) : 1;
  36. $this->fileds    = $fields;
  37. $this->pagesize  = $_CFG['pagesize'];
  38. $this->baseurl   = ($baseurl!=false) ? $baseurl : $this->__geturl();
  39. $this->pagelist  = $_CFG['pagelist'];
  40. $this->where     = $where;
  41. }
  42.  
  43. #获得当前url
  44. function __geturl()
  45. {
  46. $str = ereg_replace(sprintf("(^|&)page=%d",$this->page),"",$_SERVER['QUERY_STRING']);
  47. return $str=="" ? '?' : $str;
  48. }
  49. #获得记录集
  50. function __getlist()
  51. {
  52.      #获得count记录
  53. $sql = sprintf("SELECT COUNT(0) AS table_count FROM %s",$this->table);
  54. $rs = $this->db->Execute( $sql );
  55. $this->count = $rs->fields['table_count'];
  56.      $offset = ($this->page-1)*$this->pagesize-1;
  57.      $sql = sprintf("SELECT %s FROM %s %s",$this->fileds,$this->table,(($this->where!=false) ? " WHERE ".$this->where : ''));
  58. $rs = $this->db->SelectLimit( $sql , $this->pagesize , $offset );
  59. $list = false;
  60. while(!$rs->EOF)
  61. {
  62.      $list[] = $rs->fields;
  63. $rs->MoveNext();
  64. }
  65. return $list;
  66. }
  67.  
  68. #获得分页列表
  69. function __getpagelist()
  70. {
  71. $this->result['count'] = $this->count;
  72. $this->result['page'] = $this->page;
  73. $this->result['pagesize'] = $this->pagesize;
  74. $this->result['pagecount'] = ceil($this->count/$this->pagesize);
  75. if($this->result['pagecount']<=1) //只有一页以下
  76. {
  77. $this->result['pagelist'] = 0;
  78. }
  79. else //一页以上
  80. {
  81. #前一页,第一页的算法
  82. $this->result['first'] = ($this->page == 1) ? 0 : 1;
  83. $this->result['pre'] = ($this->page == 1) ? 0 : 1;
  84. #后一页,最后一页的算法
  85. $this->result['next'] = ($this->page == $this->pagecount ) ? 0 : 1;
  86. $this->result['last'] = ($this->page == $this->pagecount ) ? 0 : 1;
  87.  
  88.  
  89. #起始
  90. $pagearray = array();
  91. $start = floor(($this->page-1)/10)*10+1;
  92. for($i=0;$i<10;$i++)
  93. {
  94.      if( ($start+$i) <= $this->result['pagecount'])
  95. {
  96.      $pagearray[$i]['page'] = $start+$i;
  97. }
  98. if( ($start+$i) != $this->page )
  99. {
  100.      $pagearray[$i]['link'] = 1;
  101. }
  102. }
  103. #分页导航列表
  104. $this->result['pagelist'] = $pagearray;
  105. $this->result['baseurl'] = $this->baseurl;
  106. }
  107. return $this->result;
  108. }
  109. }
  110. ?>

smarty模版

  1. {{config_load file="Lang.Page.$lang.conf"}}<div id="page">
  2. <table>
  3.     <tr>
  4.     <td>
  5. {{#gongs#}}{{$page.count}}{{#pagecountend#}} {{#pagepagesizeper#}}{{$page.pagesize}}{{#pagepagelistper#}}{{#tiao#}}  {{#gongs#}}{{$page.pagecount}}{{#page#}} {{#pagepage#}}{{$page.page+1}}{{#page#}}
  6. </td>
  7. <td>
  8. {{if $page.pagecount>1}}
  9. {{if $page.first eq 1}}
  10. <a href="{{$page.baseurl}}">{{#pagefirst#}}</a>
  11. {{else}}
  12. {{#pagefirst#}}
  13. {{/if}}
  14. {{if $page.pre eq 1}}
  15. <a href="{{$page.baseurl}}&page={{$page.page-1}}">{{#pagepre#}}</a>
  16. {{else}}
  17. {{#pagepre#}}
  18. {{/if}}
  19. {{foreach from=$page.pagelist item=vols}}
  20.     {{if $vols.link eq 1}}
  21. <a href="{{$page.baseurl}}&page={{$vols.page}}">[{{$vols.page}}]</a>
  22. {{else}}
  23. [{{$vols.page}}]
  24. {{/if}}
  25. {{/foreach}}
  26. {{if $page.next eq 1}}
  27. <a href="{{$page.baseurl|default:"?"}}&page={{$page.page+1}}">{{#pagenext#}}</a>
  28. {{else}}
  29. {{#pagenext#}}
  30. {{/if}}
  31. {{if $page.last eq 1}}
  32. <a href="{{$page.baseurl|default:"?"}}&page={{$page.pagecount}}">{{#pageend#}}</a>
  33. {{else}}
  34. {{#pagelast#}}
  35. {{/if}}
  36. {{/if}}
  37. </td>
  38. </tr>
  39. </table>
  40. </div>

语言包内容

  1. pagecountend      = "条数据"
  2. pagepagesizeper   = "每页"
  3. pagepagesizeend   = "条"
  4. page              = "页"
  5. tiao              = "条"
  6. pagepage          = "当前第"
  7. pagefirst         = "首页"
  8. pagepre           = "上一页"
  9. pagenext          = "下一页"
  10. pagelast          = "尾页"
  11. gongs             = "共"

简单的PHP+SMARTY分页类

作者 : admin 于 2008年08月29日, 23:21:47
2008
08-29

类的代码

  1. <?php
  2. /*  Page.Class.php
  3.  *  Page
  4.  *  @link        http://www.sunboyu.cn
  5.  *  @package     OA
  6.  *  @version     V1.0
  7.  *
  8.  *  2008 08 28  sunboyu@gmail.com
  9.  */
  10.  class Page
  11.  {
  12. public $count;      #结果总数
  13. public $page;       #当前页
  14. public $pagesize;   #每页结果数
  15. public $pagecount;  #翻页数
  16. public $baseurl;    #url
  17. public $result;     #结果数组集
  18. public $pagelist;   #每翻页数
  19.  
  20. #构造函数,初始化变量
  21. function __construct( $count , $page , $pagesize , $pagelist , $baseurl = false )
  22. {
  23. $this->count     = $count;
  24. $this->page      = $page;
  25. $this->pagesize  = $pagesize;
  26. $this->baseurl   = isset($baseurl) ? $baseurl : $this->__geturl();
  27. $this->pagelist = $pagelist;
  28. }
  29.  
  30. #获得当前url
  31. function __geturl()
  32. {
  33. return ereg_replace("(^|&)page={$page}","",$_SERVER['QUERY_STRING']);
  34. }
  35.  
  36. #获得分页列表
  37. function __getpagelist()
  38. {
  39. $this->result['count'] = $this->count;
  40. $this->result['page'] = $this->page;
  41. $this->result['pagesize'] = $this->pagesize;
  42. $this->result['pagecount'] = ceil($this->count/$this->pagesize);
  43. if($this->result['pagecount']<=1) //只有一页以下
  44. {
  45. $this->result['pagelist'] = 0;
  46. }
  47. else //一页以上
  48. {
  49. #前一页,第一页的算法
  50. $this->result['first'] = ($this->page == 1) ? 0 : 1;
  51. $this->result['pre'] = ($this->page == 1) ? 0 : 1;
  52. #后一页,最后一页的算法
  53. $this->result['next'] = ($this->page == $this->pagecount ) ? 0 : 1;
  54. $this->result['last'] = ($this->page == $this->pagecount ) ? 0 : 1;
  55.  
  56.  
  57. #起始
  58. $pagearray = array();
  59. $start = floor(($this->page-1)/10)*10+1;
  60. for($i=0;$i<10;$i++)
  61. {
  62.      if( ($start+$i) <= $this->result['pagecount'])
  63. {
  64.      $pagearray[$i]['page'] = $start+$i;
  65. }
  66. if( ($start+$i) != $this->page )
  67. {
  68.      $pagearray[$i]['link'] = 1;
  69. }
  70. }
  71. #分页导航列表
  72. $this->result['pagelist'] = $pagearray;
  73. $this->result['baseurl'] = $this->baseurl;
  74. }
  75. }
  76. }
  77. ?>

模版代码

  1. <table>
  2.     <tr>
  3.     <td>
  4. 共{{$page.count}}条数据 每页{{$page.pagesize}}条 共{{$page.pagecount}}页 当前第{{$page.page}}页
  5. </td>
  6. <td>
  7. {{if $page.first eq 1}}
  8. <a href="{{$page.baseurl}}">首页</a>
  9. {{else}}
  10. 首页
  11. {{/if}}
  12. {{if $page.pre eq 1}}
  13. <a href="{{$page.baseurl}}&page={{$page.page-1}}">上一页</a>
  14. {{else}}
  15. 上一页
  16. {{/if}}
  17. {{foreach from=$page.pagelist item=vols}}
  18.     {{if $vols.link eq 1}}
  19. <a href="{{$page.baseurl}}&page={{$vols.page}}">[{{$vols.page}}]</a>
  20. {{else}}
  21. [{{$vols.page}}]
  22. {{/if}}
  23. {{/foreach}}
  24. {{if $page.next eq 1}}
  25. <a href="{{$page.baseurl}}&page={{$page.page-1}}">下一页</a>
  26. {{else}}
  27. 下一页
  28. {{/if}}
  29. {{if $page.last eq 1}}
  30. <a href="{{$page.baseurl}}&page={{$page.pagecount}}">尾页</a>
  31. {{else}}
  32. 尾页
  33. {{/if}}
  34. </td>
  35. </tr>
  36. </table>

调用范例

  1. <?php
  2. require_once('Include/Init.inc.php');
  3. require_once('Include/Class/Page.Class.php');
  4. $page = new Page( 999 , 12 , 10 , 6 , '?' );
  5. $page->__getpagelist();
  6. $smarty->assign("page",$page->result);
  7. $smarty->display("page.html");
  8. ?>

PHP中FTP模块的一些应用

作者 : admin 于 2008年08月27日, 10:20:06
2008
08-27
  1. <?php
  2. class ftp
  3. {
  4. //connect id
  5. var $ftp;
  6. //remote dir
  7. var $remotedir = '/';
  8. //local dir
  9. var $localdir = './';
  10. //write log
  11. var $writelog = false;
  12. //log file
  13. var $logfile = 'ftp_log.txt';
  14. //print log
  15. var $printlog = false;
  16. //session time
  17. var $timeout = 60;
  18. //construct connetc
  19. function __construct( $host , $user , $pass )
  20. {
  21. $this->ftp = @ftp_connect( $host );
  22. ftp_login( $this->ftp, $user , $pass );
  23. //ftp_set_option( $this->ftp , FTP_TIMEOUT_SEC , $this->timeout );
  24. }
  25. //list sub files
  26. function __list( $dir = false , $subtree = false )
  27. {
  28. $rlist = array();
  29. if(!$dir)
  30. {
  31. $dir = $this->remotedir;
  32. }
  33. $list = ftp_rawlist($this->ftp,$dir,TRUE);
  34. if(is_array($list))
  35. {
  36. foreach( $list as $key => $value )
  37. {
  38. $tmp = explode( ' ' , $value );
  39. $rlist[$key] = end($tmp);
  40. if(@ftp_chdir($this->ftp,$dir.$rlist[$key].'/'))
  41. {
  42. $rlist[$rlist[$key]] = $this->__list( $dir.$rlist[$key].'/' );
  43. unset($rlist[$key]);
  44. }
  45. unset($tmp);
  46. }
  47. }
  48. return $rlist;
  49. }
  50. //change dir  $isabs = false,use rela dir default
  51. function __chdir( $dir , $isabs = false )
  52. {
  53. if(!$isabs)
  54. {
  55. $nextdir = $this->remotedir.$dir.'/';
  56. }
  57. else
  58. {
  59. $nextdir = $dir;
  60. }
  61. if(ftp_chdir($this->ftp,$nextdir))
  62. {
  63. $this->remotedir = $nextdir;
  64. return true;
  65. }
  66. else
  67. {
  68. return false;
  69. }
  70. }
  71. //close connect
  72. function __close()
  73. {
  74. @ftp_close($this->ftp);
  75. }
  76. }
  77. $ftp = new ftp( 'www.sunboyu.cn' , '**', '***' );
  78. $ftp->__chdir('website',0);
  79. $list = $ftp->__list('/');
  80. echo $a = time();
  81. print_r($list);
  82. echo time() - $a;
  83. ?>

放弃ADODB_lite数据字典功能

作者 : admin 于 2008年08月26日, 23:33:31
2008
08-26

对adodb_lite的数据字典功能进行测试使用后,发现这玩意是一块鸡肋。其优秀之处在于多种数据库的无缝切换,当使用范围扩大的时候,弊端随之暴露:

1:对字段类型的支持不够完全,比如enum类型

2:不支持存储过程触发器之类

而一个项目中,存储过程触发器之类使用很多,没有这些,但出写表的数据字典感觉意义不大,不过简单的表还是会用这种方式,其他的就爹生成sql语句了

小一探针

作者 : admin 于 2008年08月21日, 11:26:28
2008
08-21

闲来没事,突然想写个探针
http://www.sunboyu.cn/info.php
难点很多,逐一突破。写这么个东西对PHP和系统的认识提高很快。

史上最牛的中文验证码,2过腾讯!

作者 : admin 于 2008年08月18日, 23:39:02
2008
08-18

测试地址 http://www.sunboyu.cn/sourse/nbcode.php

下载地址 http://www.sunboyu.cn/sourse/nbcode.rar

 Page 7 of 10  « First  ... « 5  6  7  8  9 » ...  Last »