layer-8/app/db_connector.php

28 lines
855 B
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') {
$params = array('search' => $search, 'sort' => $sort, 'sdir' => $sdir);
$stmt = $pdo->prepare("SELECT * FROM images WHERE img_title LIKE CONCAT('%', :search ,'%') ORDER BY :sort :sdir;");
$stmt->execute($params);
$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;
}