Database Check'; global $wpdb; $table_name = $wpdb->prefix . 'pc_hfap_snippets'; echo '
Table name: ' . $table_name . '
'; // Check if table exists $table_exists = $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $table_name)); if ($table_name === $table_exists) { echo '✓ Table exists!
'; // Count snippets $count = $wpdb->get_var("SELECT COUNT(*) FROM $table_name"); echo 'Total snippets: ' . $count . '
'; // Try to insert a test snippet $result = $wpdb->insert( $table_name, array( 'title' => 'Database Test ' . date('Y-m-d H:i:s'), 'location' => 'header', 'code' => '' ), array('%s', '%s', '%s') ); if ($result) { echo '✓ Insert successful! ID: ' . $wpdb->insert_id . '
'; // Delete the test $wpdb->query("DELETE FROM $table_name WHERE title LIKE 'Database Test%'"); echo '✓ Test snippet deleted
'; } else { echo '✗ Insert failed!
'; echo 'Error: ' . $wpdb->last_error . '
'; } } else { echo '✗ Table does not exist!
'; echo 'Attempting to create table...
'; // Create table $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE IF NOT EXISTS $table_name ( id mediumint(9) NOT NULL AUTO_INCREMENT, title varchar(255) NOT NULL, location enum('header','footer','body') NOT NULL DEFAULT 'header', code longtext NOT NULL, created_at datetime DEFAULT CURRENT_TIMESTAMP, updated_at datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (id) ) $charset_collate;"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta($sql); // Check again $table_exists = $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $table_name)); if ($table_name === $table_exists) { echo '✓ Table created successfully!
'; } else { echo '✗ Failed to create table!
'; echo 'Error: ' . $wpdb->last_error . '
'; } } echo 'DB Host: ' . DB_HOST . '
'; echo 'DB Name: ' . DB_NAME . '
'; echo 'Table Prefix: ' . $wpdb->prefix . '
';