私は 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')");
db クラスをアカウント クラスに参加させるにはどうすればよいですか?
次のようなことができるモデルを維持したいと思います。
$account->register('$_POST['login']', '$_POST['password']', '$_POST['email']');
これを行うためのより良い方法がない限り。
OOPの初心者なので、ヒントやガイドラインをいただければ幸いです。