php-dev-container-starter/app/public/function/function.php
2024-02-16 09:01:27 +01:00

68 lines
1.5 KiB
PHP

<?php
/*
Ajmi Yasmin, 13.02.2024
Funktionen/Prozeduren
*/
function getSite($site){
if(isset($_GET['site'])){
include_once('sites/'.$_GET['site'].'.php');
}else{
include_once('sites/'.$site.'.php');
}
}
function makeStatment($query, $params = null) {
try {
global $con;
$stmt = $con->prepare($query);
$stmt->execute($params);
return $stmt;
} catch (Exception $e) {
return $e;
}
}
function makeTable($query, $params = null)
{
$stmt = makeStatment($query, $params);
if($stmt instanceof Exception) {
echo ''. $stmt->getMessage() .'';
} else {
// Tabelle erstellen
$meta = array();
//Spaltenüberschribt dynamisch
echo '<table class="table">
<tr>';
for ($i=0; $i < $stmt->columnCount(); $i++) {
$meta[] = $stmt->getColumnMeta($i);
echo '<th>'.$meta[$i]['name'].'</th>';
}
echo '</tr>';
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo'<tr>';
foreach ($row as $r) {
echo '<td>'.$r.'</td>';
}
echo '</tr>';
}
echo '</table>';
}
}
function insertInto($tablename, $columnlist, $valuelist) {
global $con;
$query = 'INSERT INTO '.$tablename.' ('.implode(',',$columnlist).') VALUES(?)';
$params = array(implode(',', $valuelist));
$stmt = makeStatment($query, $params);
if($stmt instanceof Exception) {
return $stmt;
} else {
return true;
}
}