<?php
// PHP script to reset MySQL password
echo "Attempting to connect to MySQL...\n";

try {
    // Connect without password (should work in safe mode)
    $pdo = new PDO('mysql:host=127.0.0.1;port=3306', 'root', '');
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    echo "Connected! Resetting password...\n";
    
    // Reset password commands
    $pdo->exec("FLUSH PRIVILEGES");
    $pdo->exec("ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ''");
    $pdo->exec("ALTER USER 'root'@'127.0.0.1' IDENTIFIED WITH mysql_native_password BY ''");
    $pdo->exec("FLUSH PRIVILEGES");
    
    echo "✓ Password reset successfully!\n";
    
} catch (PDOException $e) {
    echo "✗ Error: " . $e->getMessage() . "\n";
    exit(1);
}
