42 lines
778 B
PHP
42 lines
778 B
PHP
<?php
|
|
function getArticles(){
|
|
require("lib/db.php");
|
|
|
|
$req = $db->prepare("SELECT * FROM articles");
|
|
|
|
if($req->execute(array())){
|
|
$list = array();
|
|
|
|
while($data = $req->fetch())
|
|
$list[] = $data;
|
|
}else
|
|
$list = NULL;
|
|
|
|
return $list;
|
|
}
|
|
|
|
function newArticle($title, $description, $author, $content){
|
|
require("lib/db.php");
|
|
|
|
$req = $db->prepare("INSERT INTO articles (title, description, author, date, content) VALUES (?, ?, ?, NOW(), ?)");
|
|
|
|
if($req->execute(array($title, $description, $author, $content))){
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
function getArticle($ID){
|
|
require("lib/db.php");
|
|
|
|
$req = $db->prepare("SELECT * FROM articles WHERE ID = ?");
|
|
|
|
if($req->execute(array($ID))){
|
|
if($data = $req->fetch())
|
|
return $data;
|
|
}
|
|
|
|
return false;
|
|
}
|