1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| Class Messages{
private $_db;
const HOST = "localhost";
const USER = "user";
const PASS = "mdp";
const DBNAME = "siteperso";
public function __construct(){
try {
echo('la connexion est ok');
$this->_db = new PDO("mysql:host=".self::HOST.";dbname=".self::DBNAME,self::USER,self::PASS);
} catch (PDOException $e) {
echo $e->getMessage();
}
}
public function addMessage($array){
$stmt = $this->_db->prepare('INSERT INTO messages(firstname,lastname,email,website,phone,message,datePosted)
VALUES(:f,:l,:e,:w,:p,:m,:dP)');
$stmt->execute(array(
"f" => $array['firstname'],
"l" => $array['lastname'],
"e" => $array['email'],
"w" => $array['website'],
"p" => $array['phone'],
"m" => $array['message'],
"dP" => date('Y-m-d H:i:s')
));
return $this->_db->lastInsertId();
}
} |
Partager