全部博文(921)
分类:
2007-01-03 09:18:29
php
$_DB[host] = 'localhost'; #数据库IP
$_DB[user] = 'root'; #用户名
$_DB[pass] = 'root'; #数据库密码
$_DB[name] = 'yop'; #数据库名
$_DB[type] = 'mysql'; #类型
?>
$db = &ADONewConnection($_DB[type]);
$db ->Connect($_DB[host],$_DB[user],$_DB[pass],$_DB[name]); #adodb链接
$tpl=new Smarty;
$tpl->template_dir="./templates";
$tpl->compile_dir="./templates/templates_c";
$tpl->left_delimiter = '<{';
$tpl->right_delimiter = '}>';
?>
php
include_once('./configs/config.inc.php'); #加载数据链接配置
include_once('./adodb/adodb.inc.php'); #加载adodb数据类
include_once('./smarty/Smarty.class.php'); #加载smarty模板类
include_once('./smarty_adodb.inc.php'); #加载smarty及adodb类调用集合文件
include_once('./dataclass/class_test.php'); #加载HOBBY数据类
?>
php
class Test {
function getTest_ByID($id) {
global $db;
if ( empty($id) ) {
return false;
}
$sql = "SELECT * FROM `Test` where ID='$id'";
$result = $db->Execute($sql);
$data = $result->FetchRow();
return $data;
}
function listTest($order='ID') {
global $db;
if( empty($order) ){
$order = 'ID';
}
$sql = "SELECT * FROM `Test` order by $order desc";
$result = $db->Execute($sql);
$rs = array();
while ( $data = $result->FetchRow() ) {
array_push($rs,$data);
}
return $rs;
}
function setTest($id='',$pairs,$work=''){
global $db;
if(empty($id)){
$sql = " insert into Test ";
$sql .= " ( " . join(array_keys($pairs),",") . " ) ";
$sql .= " values ";
$sql .= " ( "" . join(array_values($pairs),"","") . "" ) ";
}else{
if($work=='update'){
$sql = " $work Test ";
array_walk($pairs, create_function('&$value,&$name','$value = $name . "="" . $value . """; ') );
$sql .= " set " . join(array_values($pairs),",");
$sql .= " where id=$id";
}elseif($work=='delete'){
$sql = "$work from Test where ID='$id'";
}
}
$result = $db->Execute($sql);
return $result;
}
}
?>
php
include_once('./include.inc.php');
$test = new Test();
$rs = $test->listTest();
foreach ( $rs as $array ) {
$list[]=$array;
$tpl->assign("list",$list);
}
$tpl->display("test.htm");
$info=array("name"=>"无喱头","addtime"=>date("Y-m-d"));
$test->setTest('5',$info,'update');
?>
<{section name=sec loop=$list}>
<{$list[sec].name}>
<BR>
<{/section}>