易截截图软件、单文件、免安装、纯绿色、仅160KB

PHP的CRUD类

因为项目需要,所以自己写了一个CRUD类
虽然还比较简单,不过感觉很实用。
注:cls_database是一个数据库操作类
见:http://code.google.com/p/cyy0523xc/source/browse/trunk/php/cls_crud.php
<?php
/**
* 自动化数据表操作类
* @author 小蔡 <cyy0523xc@gmail.com>
* @version 1.0
*/
class cls_crud extends cls_database
{
/**
* 数据表名
* @var string
*/
private $table = '';
/**
* 构造函数
* @param array $config 配置变量
*/
public function __construct($config)
{
if(!empty($config))
{
foreach($config as $cf => $val)
{
$this->$cf = $val;
}
}
parent::__construct();
}
/**
* 设置数据表(例如:在操作的过程中需要改变数据表,就可以使用此方法)
* @param string $table
*/
public function set_table($table)
{
$this->table = $table;
}
/**
* 读取一条记录
* @param string $id 主键
* @param string $fields 获取字段
* @return array
*/
public function read($id, $fields='*')
{
$sql = "SELECT {$fields} from `{$this->table}` WHERE `id`='{$id}'";
$this->query($sql);
return $this->fetch_one();
}
/**
* 插入一条记录
* @param array $array 数组
* @return bool
*/
public function insert($array)
{
$fields = array();
$values = array();
foreach($array as $f => $v)
{
$fields[] = "`{$f}`";
$values[] = "'".mysql_real_escape_string($v)."'";
}
$fields = implode(',', $fields);
$values = implode(',', $values);
$sql = "INSERT INTO `{$this->table}`({$fields}) VALUES({$values})";
return $this->query($sql);
}
/**
* 更新一条记录
* @param int $id 主键
* @param array $array 数据数组


相关文档:

PHP小实例 制作留言本

PHP小实例-制作留言本
第一步:在mysql中新建数据库bbs 然后执行sql代码
CREATE TABLE `message` (
`id` tinyint(1) NOT NULL auto_increment,
`user` varchar(25) NOT NULL,
`title` varchar(50) NOT NULL,
`content` tinytext NOT NULL,
`lastdate` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT ......

php date()函数说明

string date ( string format [, int timestamp] )     //其中timestamp为可选,默认值为time();
date("1");    //Monday
date("m.d.y");   //12.21.09
date("m.d.Y");//12.21.2009
$tomorrow  = mktime(0, 0, 0, date("m")  , date("d")+1, date("Y"));
$las ......

实例讲解php实现中文水印的代码

以下是利用php实现中文水印的代码。
<?php
Header("Content-type: image/png");      /*通知浏览器,要输出图像*/
$im       = imagecreate(400 , 300);        /*定义图像的大小*/
$gray     = Ima ......

(PHP)CRUD类及分页类

之前写的crud类实在比较简单(http://blog.csdn.net/yycai/archive/2009/12/15/5012353.aspx),重新封装了一下:
<?php
/**
* 自动化数据表操作类
* @example
* <code>
* $db = cls_crud::factory(array('table'=>'article'));
* $data = $db->get_block_list(array('category_id' => 3), ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号