私はこれまでにこれを試しました...
class Test {
public $table = 'users'
public $fields = ('id', 'username', 'password');
public $id = "";
public $username = "yousufiqbal";
public $password = "123456";
public function fields_to_string(){
foreach ($fields as $field) {
// some stuff here
}
}
public function properties_to_string(){
// some stuff here
}
public function insert(){
global $dbh;
$sql = "INSERT INTO {$this->table} ($this->fields_to_string()) VALUES ($this->properties_to_string());";
$dbh->exec($sql);
}
}