我需要獲取數據,檢查併發送到數據庫。用PHP OOP編程。php oop和mysql
你能告訴我,我的班級結構是否好,以及如何dislpay所有數據?謝謝
<?php
class Database{
private $DBhost = 'localhost';
private $DBuser = 'root';
private $DBpass = 'root';
private $DBname = 'blog';
public function connect(){
//Connect to mysql db
}
public function select($rows){
//select data from db
}
public function insert($rows){
//Insert data to db
}
public function delete($rows){
//Delete data from db
}
}
class CheckData{
public $number1;
public $number2;
public function __construct(){
$this->number1 = $_POST['number1'];
$this->number2 = $_POST['number2'];
}
function ISempty(){
if(!empty($this->$number1)){
echo "Not Empty";
$data = new Database();
$data->insert($this->$number1);
}
else{
echo "Empty1";
}
if(!empty($this->$number2)){
echo "Not Empty";
$data = new Database();
$data->insert($this->$number2);
}
else{
echo "Empty2";
}
}
}
class DisplayData{
//How print all data?
function DisplayNumber(){
$data = new Database();
$data->select();
}
}
$check = new CheckData();
$check->ISempty();
$display = new DisplayData()
$display->DisplayNumber();
?>
班級結構很好,但是,我看到一個哎呀。 「ISempty」方法可能應該是「isEmpty」,以避免他人閱讀代碼時出錯。當我看到「ISempty」(界面名爲「Sempty」lol)時,我最初認爲您正在引用一個界面。此外,我可能會自己抽象數據庫類,並通過任何項目使其可重用(無需重新編碼數據庫憑據)。 – Zack 2010-05-27 18:47:39