我已经开始学习 OOP 并且我已经建立了一个名为 accountactions 的类,我想知道我是否写得很好。
该类在文件中:accountactions.class.php。
<?php
class accountactions(){
public function register($login, $password, $email){
//Zapisujemy dane wysłane formularzem
$this->username = mysql_real_escape_string($login);
$this->password = mysql_real_escape_string($password);
$this->email = mysql_real_escape_string($email);
//Hash password
$this->password = md5(sha1($this->password));
$db->simplequery("INSERT INTO radio_users(id, username, password, email) VALUES('', '$this->username', '$this->password', '$this->email')");
}
}
?>
register.php 文件:
<?php
require_once("accountactions.class.php");
$account = new accountactions();
$account->register('samplelogin', 'samplepassword', 'sample@email');
?>
我对这个片段有一些问题:
$db->simplequery("INSERT INTO radio_users(id, username, password, email) VALUES('', '$this->username', '$this->password', '$this->email')");
如何将我的数据库类加入我的帐户类?
我想保留一个模型,我可以在其中执行以下操作:
$account->register('$_POST['login']', '$_POST['password']', '$_POST['email']');
除非有更好的方法来做到这一点。
我是 OOP 的新手,所以任何提示和指南都值得赞赏。