Hi.
<?php
define('CONN_STRING', 'mysql:host=;dbname=');
define('DB_USER', '');
define('DB_PASSWORD', '');
function checkQuery($sth){
$err= $sth->errorInfo();
if(count($err)>1){
throw new PDOException($err[2]);
}
}
class RegisteModel{
private $db= null;
public function __construct(PDO $db){
$this->db= $db;
}
public function insert($name,$password,$email,$uid){
$sql= "INSERT INTO users (user_ID, user_name, user_password,user_email, user_confirm, user_is_admin, user_date, user_uid)
VALUES(NULL,:name,MD5(:password),:email,'0','0',NOW(),:uid)";
$sth= $this->db->prepare($sql);
$excute= array(':name'=>$name,':password'=>$password,':email'=>$email,':uid'=>$uid);
$sth->execute($excute);
checkQuery($sth);
return $this->db->lastInsertId();
}
}
try{
$db= new PDO(CONN_STRING, DB_USER, DB_PASSWORD);
$registerModel= new RegisteModel($db);
echo $registerModel->insert('91$name','5$password','1$email','1$uid');
$db = null;
}catch(PDOException $e){
echo $e->getMessage();
exit();
}
?>
I think it's quite useless to extends the class RegisteModel
to check the query therefore I made the function :o
Could anyone tell me what sort of system you can use in this case OOP
speaking ?
Thanks.
Bye