layer-8/app/db_connector.php

35 lines
1.1 KiB
PHP
Executable File

<?php
$pdo;
try {
$pdo = new PDO($dsn, $user, $passwd);
// if ($pdo) echo "Connected to the $dbname database successfully!";
} catch (PDOException $e) {
echo $e->getMessage();
}
function get_images($pdo, $search='%', $sort='img_date', $sdir='DESC') {
if ($sort != 'img_date' && $sdir != 'ASC') {
if ($sort != 'img_title' && $sdir != 'DESC') {
echo('Ey boss, database request is kinda f*cked up. Maybe you want to try that again, hey...<br>'.$sort.' '.$sdir);
die();
}
}
$params = array('search' => $search);
$stmt = $pdo->prepare("SELECT * FROM images WHERE img_title LIKE CONCAT('%', :search ,'%') ORDER BY $sort $sdir;");
$stmt->execute($params);
// $stmt->debugDumpParams();
$data = $stmt->fetchAll();
$img_list = '<ul class="img_list">';
foreach ($data as $block) {
$img_list .= '<li>';
$img_list .= '<img src=\''.$block['img_path'].'\'><br>';
$img_list .= '<h4>'.$block['img_title']."<br></h4>";
$img_list .= '<p>'.$block['img_desc']."</p>";
$img_list .= '</li>';
}
$img_list .= '</ul>';
echo $img_list;
}