<?php
global $mysqli;
$mysqli=false;
function connectDB(){
global $mysqli;
$mysqli = new mysqli("localhost","root","","mysyte-local");
$mysqli->query("SET NAMES utf-8");
}
function closeDB(){
global $mysqli;
$mysqli->close();
}
function getAllArticles(){
return getAll("articles");
}
function getAllBanners(){
return getAll("banners");
}
function getAll($table){
global $mysqli;
connectDB();
$result_set = $mysqli->query("SELECT* FROM `$table`");
closeDB();
return resultSetToArray($result_set);
}
function resultSetToArray($result_set){
$array=array();
while (($row = $result_set -> fetch_assoc())!=false)
$array[] =$row;
return $array;
}
?>