function addinfo($dateArr = array(),$table)
{
foreach ($dateArr as $k=>$v){
if(empty($fields))
$fields = $k;
else
$fields .= ','.$k;
if(empty($values))
$values = "'".$v."'";
else
$values .= ','."'".$v."'";
}
$query = "insert into {$table} ($fields) values($values)";
$result = $this->Execute( $query );
if( !$result )
return false;
return $this->_db->Insert_ID();
}
//查询
function getList($fileds = array('*'), $where = array(), $group = array(), $order = array(), $start = 1, $end = 1000){
$sql [] = 'select ';
$sql [] = implode ( ',', $fileds );
$sql [] = ' from ' . $this->table;
$sql [] = ! empty ( $where ) ? ' where ' . implode ( ' and ', $where ) : '';
$sql [] = ! empty ( $group ) ? ' group by ' . implode ( ',', $group ) : '';
$sql [] = ! empty ( $order ) ? ' order by ' . implode ( ',', $order ) : '';
$sql [] = ' limit ' . (($start-1) * $end) . ',' . $end;
$query = implode ( ' ', $sql );
//echo $query;exit;
$Infos = array ();
$result = $this->Execute ( $query );
$this->setListCountSql ( $where, array ($this->table ) );
if (! $result)
return $Infos;
if ($result->RecordCount () == 0) {
$result->Close ();
return $Infos;
}
while ( $row = $result->FetchRow () ) {
$Infos [] = $row;
}
$result->Close ();
return $Infos;
}
function setListCountSql($where=array()) {
$sql= 'select count(*) as num from '.$this->table;
$sql .= !empty($where) ? ' where ' . implode(' and ' , $where) : '';
//echo $sql;exit;
$this->countSql = $sql;
}
function getListCount($query ='')
{
if(empty($query))
$query = $this->countSql;
//echo $this->countSql;exit;
if(empty($query)) return 0;
$result = $this->Execute( $query );
if( !$result )
return 0;
if( $result->RecordCount() == 0 ){
$result->Close();
return 0;
}
$row = $result->FetchRow();
$num = $row["num"];
$result->Close();
return $num;
}
function getInfoById($id, $flag=0)
{
$query = "select * from $this->table where id = '$id'";
$result = $this->Execute( $query );
if( !$result )
return $Infos;
if( $result->RecordCount() == 0 ){
$result->Close();
return $Infos;
}
if($flag==0){
while( $row = $result->FetchRow()) {
$Infos[] = $row ;
}
}
else{
while( $row = $result->FetchRow()) {
$Infos[] = $this->mapRow( $row, 1 );
}
}
$result->Close();
return $Infos;
}
本文永久链接: http://www.zzxj.net/blog/fxs_2008/archive/2009/12/01/104.html
发表于 @ 2009年12月01日 |评论(loading... )|收藏