Andromeda22
Новичок
Дата регистрации:
09.01.2016 20:51:45
Сообщений: 1
Этот код выдает такую ошибку:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '[email protected]' for key 'email'' in Z:\home\localhost\www\testcomment12\constryct.php:42 Stack trace: #0 Z:\home\localhost\www\testcomment12\constryct.php(42): PDOStatement->execute(Array) #1 Z:\home\localhost\www\testcomment12\constryct.php(47): Info->intoDb() #2 {main} thrown in Z:\home\localhost\www\testcomment12\constryct.php on line 42.
Помогите пожалуйста, я новичек в этом деле
class DB
{
static function connect($host ='localhost', $user ='root', $pass = '', $dbname ='testcomment'
{
$dsn = 'mysql:host='.$host.';dbname='.$dbname.';charset=utf8;';
$opt = array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE=>PDO::FETCH_ASSOC);
$pdo = new PDO($dsn, $user, $pass, $opt);
$pdo->query('set names "utf8"';
return $pdo;
}
}
class Info {
protected $id;
protected $username;
protected $email;
protected $phone;
protected $comment;
protected $filepath;
protected $date;
function __construct($id,$us,$em,$ph,$com,$fp){
$this->id =$id;
$this->username = $us;
$this->email = $em;
$this->phone = $ph;
$this->comment = $com;
$this->filepath = $fp;
$this->date = @date("Y-m-d H:i:s"
}
function intoDb()
{
$pdo =DB::connect();
$res =$pdo->prepare('insert into Usercomment(username, email, phone, comment, filepath, date) values( ?, ?, ?, ?, ?, ?)';
$res->execute(array($this->username, $this->email, $this->phone, $this->comment, $this->filepath, @date("Y-m-d H:i:s"));
}
}
$f3=new Info(0,"Pety", "[email protected]",2345678, "Yes", "text.txt"
$f3->intoDb();
?>.