bibena/blog — Issue #5: lib.php
Author: bibena
Created: 2011-12-26 13:38:58+00:00
State: open

db=$db;
}
function getclassname()
{
}
function execute(array $fields)
{
$field='';
$value='';
$isfirst=true;
foreach($fields as $field=>$value)
{
if(!$isfirst)
{
$sqlfields.=',';
$sqlvalues.=',';
}
$sqlfields.="`$field`";
$sqlvalues.="'$value'";
$isfirst=false;
}
return array(mysql_escape_string($sqlfields),$sqlvalues);
}
function select(array $fields,$where=NULL,$distinct=0,$sort=0)
{
$field='';
$isfirst=true;
$sql="SELECT ";
if($distinct===1)
{
$sql.="DISTINCT ";
}
foreach($fields as $field)
{
if(!$isfirst)
{
$sql.=',';
}
$sql.="`$field`";
$isfirst=false;
}
$sql.=" FROM ".$this->getclassname();
if(!is_null($where) && is_array($where))
{
$sql.=" WHERE ".$where[0]."=".$where[1];
}
if($sort!==0)
{
$sql.=" ORDER BY ".$sort." DESC";
}
return $this->db->query($sql);
}
function iselect(array $fields,$innerj,array $on,array$where)
{
$field='';
$isfirst=true;
$sql="SELECT ";
foreach($fields as $field)
{
if(!$isfirst)
{
$sql.=',';
}
$sql.="$field";
$isfirst=false;
}
$sql.=" FROM ".$this->getclassname();
$sql.=" INNER JOIN ".$innerj;
$sql.=" ON (".$on[0]."=".$on[1].")";
$sql.=" WHERE ".$where[0]."='".$where[1]."'";
return $this->db->query($sql);
}
}
abstract class table extends protable
{
public function insert(array $fields)
{
$execute=$this->execute($fields);
$sql="INSERT INTO ".$this->getclassname()."	(".$execute[0].") VALUES (".$execute[1].")";
return $this->db->query($sql);
}
public function delete(array $fields)
{
$execute=$this->execute($fields);
$sql="DELETE FROM ".$this->getclassname()." WHERE ".$execute[0]."=".$execute[1];
file_put_contents('file.txt',$sql);

return $this->db->query($sql);
}
}
class blog extends table
{
function getclassname()
{
return __CLASS__;
}
}
class blog_tags extends table
{
function getclassname()
{
return __CLASS__;
}
}
class tags extends table
{
function getclassname()
{
return __CLASS__;
}
}
?>