Hi.
Sorry to disturb you
but I've my doubts about this
code
class NewsModel extends Model{
public function __construct(){
parent::__construct();
}
public function insert($content,$imageName,$imageFile){
try{
$sql= 'INSERT INTO news (news_id, news_content, news_image_name, news_image_file, news_date )';
$sql .= 'VALUES (NULL , :content, :imageName, :imageFile, NOW())';
$sth= $this->conn->pdo->prepare($sql);
$excute= array(
':content'=>$content,
':imageName'=>$imageName,
':imageFile'=>$imageFile
);
$sth->execute($excute);
}
catch(PDOException $e){
throw new FormattingException($e->getMessage(),0,$e);
}
}
public function all(){
try{
$sql= 'SELECT news_id, news_content, news_image_name, news_image_file,';
$sql.= "CONCAT(date_format( news_date, '%d' ),' ',elt( month( news_date ) ,'Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre' ),' ',";
$sql.= "date_format( news_date, '%Y' )) AS full_date FROM news ORDER BY news_id DESC";
return $this->conn->fetchObject($sql);
}
catch(PDOException $e){
throw new FormattingException($e->getMessage(),0,$e);
}
}
public function select($id){
try{
$sql= 'SELECT news_id, news_content, news_image_name, news_image_file,';
$sql.= "CONCAT(date_format( news_date, '%d' ),' ',elt( month( news_date ) ,'Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre' ),' ',";
$sql.= "date_format( news_date, '%Y' )) AS full_date FROM news WHERE news_id=:id LIMIT 1";
$excute= array(
':id'=>$id
);
return $this->conn->fetchObject($sql,$excute);
}
catch(PDOException $e){
throw new FormattingException($e->getMessage(),0,$e);
}
}
public function update($content,$imageName,$imageFile,$id){
try{
$sql= 'UPDATE news SET news_content=:content,news_image_name=:imageName,news_image_file =:imageFile ';
$sql .= 'WHERE news_id=:id LIMIT 1';
$sth= $this->conn->pdo->prepare($sql);
$excute= array(
':content'=>$content,
':imageName'=>$imageName,
':imageFile'=>$imageFile,
':id'=>$id
);
$sth->execute($excute);
}
catch(PDOException $e){
throw new FormattingException($e->getMessage(),0,$e);
}
}
public function delete($id){
try{
$sql= 'DELETE FROM news WHERE news_id=:id LIMIT 1';
$sth= $this->conn->pdo->prepare($sql);
$excute= array(':id'=>$id);
$sth->execute($excute);
}
catch(PDOException $e){
throw new FormattingException($e->getMessage(),0,$e);
}
}
}
Can I call that a model or a mapper ?
Bye.