- initial

This commit is contained in:
Ty Clifford
2026-04-24 08:41:52 -04:00
commit b57091e4ad
49 changed files with 7371 additions and 0 deletions
+117
View File
@@ -0,0 +1,117 @@
<?php
/**
* Business DB Diagnostic — shows exact queries and results
* Access: /admin/biz_debug.php
* Remove this file from production after use.
*/
require_once dirname(__DIR__).'/includes/boot.php';
requireAdmin();
header('Content-Type: text/plain; charset=utf-8');
$db = db();
echo "=== DISCOVER KEYSER WV — BUSINESS TABLE DIAGNOSTIC ===\n";
echo "Generated: ".date('Y-m-d H:i:s')."\n";
echo "DB File: ".DB_FILE."\n";
echo "DB Writable: ".(is_writable(DB_FILE)?'YES':'NO')."\n\n";
// 1. Schema
echo "--- SCHEMA (businesses table) ---\n";
$schema = $db->query("SELECT sql FROM sqlite_master WHERE type='table' AND name='businesses'")->fetchColumn();
echo $schema."\n\n";
// 2. Row count
$count = $db->query("SELECT COUNT(*) FROM businesses")->fetchColumn();
echo "--- ROW COUNT ---\n";
echo "SELECT COUNT(*) FROM businesses;\n=> $count rows\n\n";
// 3. All businesses (id, name, slug, is_active)
echo "--- ALL BUSINESSES ---\n";
echo "SELECT id, name, slug, category_id, is_active, is_featured FROM businesses ORDER BY id;\n";
$rows = $db->query("SELECT id, name, slug, category_id, is_active, is_featured FROM businesses ORDER BY id")->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $r) {
echo sprintf(" [%3d] %-40s slug=%-35s cat=%s active=%d featured=%d\n",
$r['id'], substr($r['name'],0,40), substr($r['slug'],0,35), $r['category_id'], $r['is_active'], $r['is_featured']);
}
echo "\n";
// 4. Test UPDATE with id=1
$id = isset($_GET['test_id']) ? (int)$_GET['test_id'] : 1;
$biz = $db->prepare("SELECT * FROM businesses WHERE id=?");
$biz->execute([$id]);
$row = $biz->fetch(PDO::FETCH_ASSOC);
echo "--- FETCH SINGLE ROW (id=$id) ---\n";
echo "SELECT * FROM businesses WHERE id=$id;\n";
if ($row) {
foreach ($row as $k => $v) {
echo sprintf(" %-14s = %s\n", $k, strlen($v) > 80 ? substr($v,0,80).'...' : $v);
}
} else {
echo " [NO ROW FOUND for id=$id]\n";
}
echo "\n";
// 5. Categories
echo "--- CATEGORIES ---\n";
echo "SELECT id, name, icon, sort_order FROM categories ORDER BY sort_order;\n";
$cats = $db->query("SELECT id, name, icon, sort_order FROM categories ORDER BY sort_order")->fetchAll(PDO::FETCH_ASSOC);
foreach ($cats as $c) {
echo sprintf(" [%2d] %s %s (sort=%d)\n", $c['id'], $c['icon'], $c['name'], $c['sort_order']);
}
echo "\n";
// 6. Test UPDATE statement (dry run — shows exact SQL and params)
if ($row) {
echo "--- UPDATE STATEMENT THAT WOULD BE RUN ---\n";
$sql = "UPDATE businesses SET name=?,slug=?,category_id=?,subcategory=?,description=?,address=?,phone=?,email=?,website=?,hours=?,lat=?,lng=?,is_active=?,is_featured=? WHERE id=?";
echo $sql."\n";
echo "Params (15 total):\n";
$params = [
$row['name'], $row['slug'], $row['category_id'], $row['subcategory'],
$row['description'], $row['address'], $row['phone'], $row['email'],
$row['website'], $row['hours'], $row['lat'], $row['lng'],
$row['is_active'], $row['is_featured'], $id
];
foreach ($params as $i => $v) {
echo sprintf(" [%2d] %s\n", $i+1, strlen((string)$v) > 80 ? substr($v,0,80).'...' : $v);
}
echo "\n";
// Actually execute the no-op UPDATE to verify it works
echo "--- EXECUTING NO-OP UPDATE (same values back) ---\n";
try {
$stmt = $db->prepare($sql);
$stmt->execute($params);
$affected = $stmt->rowCount();
echo "SUCCESS: $affected row(s) affected\n\n";
} catch (\Exception $ex) {
echo "ERROR: ".$ex->getMessage()."\n\n";
}
}
// 7. Duplicate slug check
echo "--- DUPLICATE SLUG CHECK ---\n";
echo "SELECT slug, COUNT(*) c FROM businesses GROUP BY slug HAVING c > 1;\n";
$dupes = $db->query("SELECT slug, COUNT(*) c FROM businesses GROUP BY slug HAVING c > 1")->fetchAll(PDO::FETCH_ASSOC);
if ($dupes) {
foreach ($dupes as $d) echo " DUPLICATE: {$d['slug']} ({$d['c']} times)\n";
} else {
echo " No duplicates found.\n";
}
echo "\n";
// 8. NULL/empty slug check
echo "--- NULL OR EMPTY SLUG CHECK ---\n";
echo "SELECT id, name, slug FROM businesses WHERE slug IS NULL OR slug='';\n";
$bad = $db->query("SELECT id, name, slug FROM businesses WHERE slug IS NULL OR slug=''")->fetchAll(PDO::FETCH_ASSOC);
if ($bad) {
foreach ($bad as $b) echo " BAD: [{$b['id']}] {$b['name']} slug=".var_export($b['slug'],true)."\n";
} else {
echo " All slugs OK.\n";
}
echo "\n";
echo "=== END DIAGNOSTIC ===\n";
echo "Tip: Add ?test_id=N to test a specific business by ID.\n";