Initial commit: 교육 프로젝트 배포
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
require __DIR__ . '/edu/bbs/db_conn.php';
|
||||
$pdo = db_conn();
|
||||
$kw = '장애인';
|
||||
$like = '%' . $kw . '%';
|
||||
|
||||
$queries = [
|
||||
'title_only_all' => "SELECT COUNT(*) FROM edu_contents WHERE title LIKE ?",
|
||||
'desc_only_all' => "SELECT COUNT(*) FROM edu_contents WHERE description LIKE ?",
|
||||
'desc2_only_all' => "SELECT COUNT(*) FROM edu_contents WHERE description2 LIKE ?",
|
||||
'all_cols_all_rows' => "SELECT COUNT(*) FROM edu_contents WHERE title LIKE ? OR description LIKE ? OR description2 LIKE ?",
|
||||
'all_cols_is_active_1' => "SELECT COUNT(*) FROM edu_contents WHERE is_active = 1 AND (title LIKE ? OR description LIKE ? OR description2 LIKE ?)",
|
||||
'all_cols_is_active_Y' => "SELECT COUNT(*) FROM edu_contents WHERE is_active = 'Y' AND (title LIKE ? OR description LIKE ? OR description2 LIKE ?)",
|
||||
];
|
||||
|
||||
foreach ($queries as $name => $sql) {
|
||||
$stmt = $pdo->prepare($sql);
|
||||
if (substr_count($sql, '?') === 1) {
|
||||
$stmt->execute([$like]);
|
||||
} else {
|
||||
$stmt->execute([$like, $like, $like]);
|
||||
}
|
||||
echo $name . '=' . (int)$stmt->fetchColumn() . PHP_EOL;
|
||||
}
|
||||
|
||||
echo "--- sample rows ---" . PHP_EOL;
|
||||
$stmt = $pdo->prepare("SELECT content_id, is_active, title FROM edu_contents WHERE title LIKE ? OR description LIKE ? OR description2 LIKE ? ORDER BY content_id DESC LIMIT 20");
|
||||
$stmt->execute([$like, $like, $like]);
|
||||
while ($r = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
echo (string)$r['content_id'] . "\t" . (string)($r['is_active'] ?? 'NULL') . "\t" . (string)$r['title'] . PHP_EOL;
|
||||
}
|
||||
Reference in New Issue
Block a user