function ConnectBd(){
mysql_connect('localhost', 'root', '');
mysql_select_db('article');
}
function ChekBD($value, $name){
ConnectBd();
$el = mysql_query("SELECT $name FROM articles WHERE $name='$value' ");
while(!false == ($row = mysql_fetch_array($el))){
$mass = $row;
}
if($mass[$name] == $value){
mysql_query("REPLACE('$name',$value, $value)");
}else{
mysql_query("INSERT INTO articles ($name) VALUES ('$value')");
}
}
class Article {
public $text;
public $title;
public $category;
public function __construct(){
ConnectBd();
}
public function view($category, $title, $text){
$this->category=$category;
$this->title=$title;
$this->text=$text;
ChekBD($this->category, 'category');
ChekBD($this->title, 'title');
ChekBD($this->text, 'texts');
}
}
$a = new Article;
$a->view('новости', 'Авария', 'Произашла крупная авария в спб');
$a = new WorkBd;
$a->connect('новости', 'Авария', 'Произашла крупная авария в спб');
var_dump($a);