在做网站后台的时候 写到最多的恐怕就是 后台 对数据库的添加修改, 一般一个企业网站 都要有对 产品 设备 公司简介 等等 的添加修改 这样就必须在后台 做一些简单而麻烦的工作:制作表单 ->提交 -> 经过JS -> PHP把$_POST 分配给变量 -> 写入数据库->提示成功或者失败 这个过程其实没有什么难度 但是对应不同的表单和不同的数据表 代码是要重新写的 。 这就耽误了很多时间 .
请问大神们 有什么办法 能提高在制作着部分的效率?
请问大神们 有什么办法 能提高在制作着部分的效率?
超强ORM数据库类http://code.google.com/p/queryphp/downloads/list
* 新增 更改 数据
*
* @table string $表明
* @array string $更改数组
* @where string $判断类型
*/
function save($table,$array,$where='',$id='')
{
global $cookievarpre;
$table = $cookievarpre.$table;
$sql = "show fields from $table";
$reset = $this->query($sql);
while ($row = $this->fetch_array($reset))
{
$list[] = $row['Field'];
}
if (!empty($where))
{
foreach ($array as $key=>$value)
{
if (in_array($key,$list))
{
//if (!empty($value))
$field[] = $key."='".$value."'";
}
}
$sql = "update $table set ".implode(',',$field)." where ".$where;
$this->query($sql);
$info = $id;
}
else
{
foreach ($array as $key=>$value)
{
if (in_array($key,$list))
{
//if (!empty($value))
//{
$field[] = $key;
$values[] = "'".$value."'";
//}
}
}
if ($id='')
$sql = "insert into $table (".implode(',',$field).") values (".implode(',',$values).")";
else
$sql = "replace into $table (".implode(',',$field).") values (".implode(',',$values).")";
$this->query($sql);
$info = $this->insert_id();
}
return $info;
}
自己扩展的DZ的MYSQL类 增加和修改的调用方法if (empty($_REQUEST['id']))
{
$_REQUEST['dtime'] = time();
$_POST['aid'] = $query->save('info',$_REQUEST);
$query->save('article',$_POST);
}
else
{
$query->save('info',$_REQUEST,' id='.$_REQUEST['id']);
$article['aid'] = $_REQUEST['id'];
$article['body'] = $_REQUEST['body'];
$query->save('article',$article,'',$_REQUEST['id']);
}
CakePHP, ORM and framework for PHP5, open source (scalars, arrays, objects). Based on database introspection. No class extending or code generation
Doctrine, Open Source ORM for PHP 5.2.3, free software (GNU LGPL)
PdoMap, Open Source ORM for PHP 5.x, inspired by Hibernate, free software (GNU LGPL)
Propel, ORM and Query-Toolkit for PHP 5, inspired by Apache Torque, free software (GNU LGPL)
Rocks, Open Source ORM for PHP 5.1 plus, free for non-commercial use (GPL)
Qcodo, ORM and framework for PHP5, open source
RapidDataMapper, Open source PHP 5.2 ORM and database abstraction which creates custom mapper code for good performance and flexibility
Redbean, ORM layer for PHP 5 that creates and maintains tables on the fly (BSD)
Torpor, Open Source ORM for PHP 5.1 plus, free software (MIT), database and OS agnostic
CRUDsader, Open Source ORM for PHP 5.1 plus, free framework(GPL)
dORM, Open Source ORM for PHP 5.2.9 (AGPL with alternate proprietary license)
Outlet, Open Source ORM for PHP 5.1.6 plus, free software (New BSD)
Repose, Open Source ORM for PHP 5.2.x plus, free software (New BSD)你可以自己搜索了研究一下, 基本上常用的framework里都含这一部分功能,那个Redbean你要有兴趣看一下, 用那个你可以根本不去关心数据库操作(建表/插入/修改/删除等),
你要做的就是设计类,怎么存储不用关心......