Hi,
For long time reading and testing, but i want know. This is correct PHP OOP code, or not
Class User {
function Add($Name, $Password){
$sql_str = "INSERT INTO User SET Name = '$Name', Password = '$Password'";
$sql->do_sql($sql_str);
}
function Del($UserID) {
$sql_str = "DELETE FROM User WHERE UserID = '$UserID'";
$sql->do_sql($sql_str);
}
function Show ($Limit)
if ($limit > 0){
$sql_str = "SELECT * FROM User ORDER BY Name LIMIT $Limit";
}else{
$sql_str = "SELECT * FROM User ORDER BY Name";
}
$result = $sql->do_sql($sql_str);
for ($i = 0; $i < COUNT($result); $i++){
$data[$i]['UserID'] = ....
$data[$i]['Name'] = ....
}
return $Data
}
}
$MyUser = new User;
And now from the file userControl.php I can control the actions. If I want to do something, I can send the action to the instance of the user class: $MyUser->Add($Name, $Password);
Is this approach more like a grouped function and not OOP or is it better to use setters and getters?
If this example not OOP, then what I do wrong and how need to do this example OOP way?
Tnx