![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/soundstudiopro.com/public_html/ |
<?php
/**
* Migration script to convert events table to utf8mb4 for emoji support
* Run this once to fix the database schema
*/
session_start();
require_once 'config/database.php';
// Only allow admin to run this
if (!isset($_SESSION['user_id']) || !isset($_SESSION['is_admin']) || !$_SESSION['is_admin']) {
die('Access denied. Admin only.');
}
$pdo = getDBConnection();
if (!$pdo) {
die('Database connection failed');
}
echo "<h1>🔧 Converting Events Table to UTF8MB4</h1>";
echo "<style>
body { font-family: Arial, sans-serif; padding: 20px; background: #1a1a1a; color: #fff; }
.success { color: #4ade80; }
.error { color: #f87171; }
.info { color: #60a5fa; }
pre { background: #2a2a2a; padding: 10px; border-radius: 5px; overflow-x: auto; }
</style>";
try {
// First, check current charset
echo "<h2>📊 Current Table Status</h2>";
$result = $pdo->query("SHOW CREATE TABLE events");
$row = $result->fetch(PDO::FETCH_ASSOC);
echo "<pre>" . htmlspecialchars($row['Create Table']) . "</pre>";
// Check current charset of description column
$result = $pdo->query("SHOW FULL COLUMNS FROM events WHERE Field = 'description'");
$col = $result->fetch(PDO::FETCH_ASSOC);
echo "<p class='info'>Current description column charset: " . ($col['Collation'] ?? 'unknown') . "</p>";
echo "<h2>🔄 Converting Table and Columns</h2>";
// Convert the entire table to utf8mb4
echo "<p>Converting events table to utf8mb4...</p>";
$pdo->exec("ALTER TABLE events CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
echo "<p class='success'>✅ Table converted to utf8mb4</p>";
// Convert specific text columns that might contain emojis
$textColumns = ['title', 'description', 'location', 'venue_name', 'address'];
foreach ($textColumns as $column) {
// Check if column exists
$result = $pdo->query("SHOW COLUMNS FROM events LIKE '$column'");
if ($result->rowCount() > 0) {
$colInfo = $result->fetch(PDO::FETCH_ASSOC);
$type = $colInfo['Type'];
// Convert to utf8mb4
echo "<p>Converting column '$column' ($type) to utf8mb4...</p>";
$pdo->exec("ALTER TABLE events MODIFY COLUMN `$column` $type CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
echo "<p class='success'>✅ Column '$column' converted</p>";
}
}
// Also convert event_comments table
echo "<h2>💬 Converting Event Comments Table</h2>";
try {
$pdo->exec("ALTER TABLE event_comments CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
$pdo->exec("ALTER TABLE event_comments MODIFY COLUMN `comment` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
echo "<p class='success'>✅ event_comments table converted</p>";
} catch (PDOException $e) {
echo "<p class='error'>⚠️ Could not convert event_comments: " . $e->getMessage() . "</p>";
}
// Also convert event_attendees notes
echo "<h2>📝 Converting Event Attendees Table</h2>";
try {
$pdo->exec("ALTER TABLE event_attendees CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
$result = $pdo->query("SHOW COLUMNS FROM event_attendees LIKE 'notes'");
if ($result->rowCount() > 0) {
$pdo->exec("ALTER TABLE event_attendees MODIFY COLUMN `notes` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
}
echo "<p class='success'>✅ event_attendees table converted</p>";
} catch (PDOException $e) {
echo "<p class='error'>⚠️ Could not convert event_attendees: " . $e->getMessage() . "</p>";
}
// Verify the conversion
echo "<h2>✅ Verification</h2>";
$result = $pdo->query("SHOW CREATE TABLE events");
$row = $result->fetch(PDO::FETCH_ASSOC);
echo "<p class='info'>Updated table structure:</p>";
echo "<pre>" . htmlspecialchars($row['Create Table']) . "</pre>";
$result = $pdo->query("SHOW FULL COLUMNS FROM events WHERE Field = 'description'");
$col = $result->fetch(PDO::FETCH_ASSOC);
echo "<p class='success'>✅ Description column charset: " . ($col['Collation'] ?? 'unknown') . "</p>";
echo "<h2 class='success'>🎉 Migration Complete!</h2>";
echo "<p class='info'><strong>Important:</strong> If your event descriptions already contain '?' characters instead of emojis, you'll need to re-enter those descriptions. The database is now ready to store emojis correctly.</p>";
} catch (PDOException $e) {
echo "<p class='error'>❌ Error: " . $e->getMessage() . "</p>";
echo "<pre>" . $e->getTraceAsString() . "</pre>";
}