test_wp_connection.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. // Simple test script to debug WordPress connection issues
  3. error_reporting(E_ALL);
  4. ini_set('display_errors', 1);
  5. echo "<h1>WordPress Connection Test</h1>";
  6. // Test basic form submission
  7. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  8. echo "<h2>Form Data Received:</h2>";
  9. echo "<pre>" . print_r($_POST, true) . "</pre>";
  10. // Test WordPress connection
  11. if (!empty($_POST['wp_host']) && !empty($_POST['wp_database']) && !empty($_POST['wp_username'])) {
  12. echo "<h2>Testing WordPress Connection...</h2>";
  13. try {
  14. $wpConfig = [
  15. 'host' => trim($_POST['wp_host']),
  16. 'database' => trim($_POST['wp_database']),
  17. 'username' => trim($_POST['wp_username']),
  18. 'password' => $_POST['wp_password'] ?? ''
  19. ];
  20. echo "<p>Config: " . htmlspecialchars($wpConfig['host']) . " / " . htmlspecialchars($wpConfig['database']) . " / " . htmlspecialchars($wpConfig['username']) . "</p>";
  21. // Test PDO connection directly
  22. $dsn = "mysql:host={$wpConfig['host']};dbname={$wpConfig['database']};charset=utf8mb4";
  23. echo "<p>DSN: " . htmlspecialchars($dsn) . "</p>";
  24. $options = [
  25. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  26. PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
  27. PDO::ATTR_TIMEOUT => 5
  28. ];
  29. $pdo = new PDO($dsn, $wpConfig['username'], $wpConfig['password'], $options);
  30. echo "<p style='color: green;'>✓ PDO Connection successful!</p>";
  31. // Test simple query
  32. $result = $pdo->query("SELECT 1 as test");
  33. echo "<p>✓ Simple query successful!</p>";
  34. // Test WordPress tables
  35. $tables = ['wp_posts', 'wp_users', 'wp_terms', 'wp_term_taxonomy', 'wp_term_relationships', 'wp_comments'];
  36. $existingTables = [];
  37. foreach ($tables as $table) {
  38. $stmt = $pdo->query("SHOW TABLES LIKE '$table'");
  39. if ($stmt->rowCount() > 0) {
  40. $existingTables[] = $table;
  41. echo "<p style='color: green;'>✓ Found table: $table</p>";
  42. } else {
  43. echo "<p style='color: orange;'>⚠ Missing table: $table</p>";
  44. }
  45. }
  46. if (count($existingTables) >= 6) {
  47. echo "<h3 style='color: green;'>WordPress database structure verified!</h3>";
  48. // Get some stats
  49. $stats = [];
  50. $stats['posts'] = $pdo->query("SELECT COUNT(*) FROM wp_posts WHERE post_type = 'post'")->fetchColumn();
  51. $stats['users'] = $pdo->query("SELECT COUNT(*) FROM wp_users")->fetchColumn();
  52. $stats['categories'] = $pdo->query("SELECT COUNT(*) FROM wp_term_taxonomy WHERE taxonomy = 'category'")->fetchColumn();
  53. $stats['comments'] = $pdo->query("SELECT COUNT(*) FROM wp_comments")->fetchColumn();
  54. echo "<h3>Database Stats:</h3>";
  55. echo "<pre>" . print_r($stats, true) . "</pre>";
  56. } else {
  57. echo "<h3 style='color: red;'>WordPress database structure incomplete!</h3>";
  58. }
  59. } catch (PDOException $e) {
  60. echo "<p style='color: red;'>✗ PDO Error: " . htmlspecialchars($e->getMessage()) . "</p>";
  61. } catch (Exception $e) {
  62. echo "<p style='color: red;'>✗ Error: " . htmlspecialchars($e->getMessage()) . "</p>";
  63. }
  64. }
  65. } else {
  66. echo "<p>Please submit the form to test connection.</p>";
  67. }
  68. ?>
  69. <h2>Test Form:</h2>
  70. <form method="post">
  71. <div style="margin-bottom: 10px;">
  72. <label>Host: <input type="text" name="wp_host" value="localhost" required></label>
  73. </div>
  74. <div style="margin-bottom: 10px;">
  75. <label>Database: <input type="text" name="wp_database" value="wordpress" required></label>
  76. </div>
  77. <div style="margin-bottom: 10px;">
  78. <label>Username: <input type="text" name="wp_username" value="wp_user" required></label>
  79. </div>
  80. <div style="margin-bottom: 10px;">
  81. <label>Password: <input type="password" name="wp_password"></label>
  82. </div>
  83. <div style="margin-bottom: 10px;">
  84. <input type="submit" value="Test Connection">
  85. </div>
  86. </form>
  87. <h2>PHP Info:</h2>
  88. <p>PDO Support: <?php echo extension_loaded('pdo') ? 'Yes' : 'No'; ?></p>
  89. <p>PDO MySQL Support: <?php echo extension_loaded('pdo_mysql') ? 'Yes' : 'No'; ?></p>
  90. <p>Memory Limit: <?php echo ini_get('memory_limit'); ?></p>
  91. <p>Max Execution Time: <?php echo ini_get('max_execution_time'); ?> seconds</p>