| @@ -325,8 +325,14 @@ | ||
| 325 | 325 | |
| 326 | 326 | // Create table using dbDelta for WordPress compatibility |
| 327 | 327 | $result = dbDelta($sql); |
| 328 | 328 | |
| 329 | + // dbDelta reports nothing when the database refuses the | |
| 330 | + // statement, so wpdb's own error is the only account of why. | |
| 331 | + // Read it now: table_exists() runs a query of its own, and | |
| 332 | + // every wpdb query starts by clearing last_error. | |
| 333 | + $db_error = (string) $this->wpdb->last_error; | |
| 334 | + | |
| 329 | 335 | // Verify table creation |
| 330 | 336 | if ($this->table_exists($full_table_name)) { |
| 331 | 337 | $results['tables_created'][] = $full_table_name; |
| 332 | 338 | |
| @@ -335,12 +341,8 @@ | ||
| 335 | 341 | |
| 336 | 342 | // Add constraints if needed |
| 337 | 343 | $this->add_table_constraints($table_name); |
| 338 | 344 | } else { |
| 339 | - // dbDelta reports nothing when the database refuses the | |
| 340 | - // statement, so wpdb's own error is the only account of why. | |
| 341 | - $db_error = (string) $this->wpdb->last_error; | |
| 342 | - | |
| 343 | 345 | $results['tables_failed'][] = $full_table_name; |
| 344 | 346 | $results['errors'][] = "Failed to create table: {$full_table_name}" |
| 345 | 347 | . ('' !== $db_error ? ' — ' . $db_error : ''); |
| 346 | 348 | $results['success'] = false; |
| @@ -663,10 +665,16 @@ | ||
| 663 | 665 | * @throws \InvalidArgumentException On failure. |
| 664 | 666 | */ |
| 665 | 667 | private function get_table_sql(string $table_name): string { |
| 666 | 668 | $full_table_name = $this->get_table_name($table_name); |
| 667 | - $charset_collate = $this->db_config['charset_collate']; | |
| 668 | 669 | |
| 670 | + // Pin the engine instead of inheriting the server's | |
| 671 | + // default_storage_engine. The indexes below assume InnoDB: MyISAM caps | |
| 672 | + // a key at 1000 bytes (seo_settings and seo_social exceed it) and | |
| 673 | + // rejects descending indexes (seo_schema), so on a server defaulting | |
| 674 | + // to MyISAM those tables were never created (#725). | |
| 675 | + $charset_collate = trim('ENGINE=InnoDB ' . $this->db_config['charset_collate']); | |
| 676 | + | |
| 669 | 677 | switch ($table_name) { |
| 670 | 678 | // SEO Tables |
| 671 | 679 | case 'seo_settings': |
| 672 | 680 | return $this->get_seo_settings_table_sql($full_table_name, $charset_collate); |
| @@ -1725,34 +1733,29 @@ | ||
| 1725 | 1733 | return (int) $result > 0; |
| 1726 | 1734 | } |
| 1727 | 1735 | |
| 1728 | 1736 | /** |
| 1729 | - * Check if MySQL supports JSON column type with caching | |
| 1737 | + * Check if the database server supports the JSON column type | |
| 1730 | 1738 | * |
| 1731 | - * Uses WordPress's built-in database version detection and caches the result | |
| 1732 | - * to avoid repeated database queries during schema creation. | |
| 1739 | + * MySQL added JSON in 5.7.8 and MariaDB in 10.2.7. MariaDB's own 10.x | |
| 1740 | + * number passes any MySQL threshold, and on older PHP the server string | |
| 1741 | + * carries a `5.5.5-` replication prefix that db_version() reads as the | |
| 1742 | + * version, so MariaDB's version is taken from the server string itself. | |
| 1743 | + * Neither lookup queries the database. | |
| 1733 | 1744 | * |
| 1734 | 1745 | * @since 1.0.0 |
| 1735 | - * @return bool True if MySQL 5.7+ supports JSON columns | |
| 1746 | + * @return bool True if the server supports JSON columns | |
| 1736 | 1747 | */ |
| 1737 | 1748 | private function get_mysql_json_support(): bool { |
| 1738 | - // Check if we have cached result | |
| 1739 | - static $json_support = null; | |
| 1740 | - | |
| 1741 | - if ($json_support !== null) { | |
| 1742 | - return $json_support; | |
| 1743 | - } | |
| 1744 | - | |
| 1745 | - // Use WordPress's built-in database version method | |
| 1746 | 1749 | global $wpdb; |
| 1747 | 1750 | |
| 1748 | - // Get MySQL version using WordPress method (safer than direct query) | |
| 1749 | - $mysql_version = $wpdb->db_version(); | |
| 1751 | + $server_info = method_exists($wpdb, 'db_server_info') ? (string) $wpdb->db_server_info() : ''; | |
| 1750 | 1752 | |
| 1751 | - // Cache the result for subsequent calls | |
| 1752 | - $json_support = version_compare($mysql_version, '5.7.0', '>='); | |
| 1753 | + if (preg_match('/(\d+(?:\.\d+)+)-MariaDB/i', $server_info, $matches)) { | |
| 1754 | + return version_compare($matches[1], '10.2.7', '>='); | |
| 1755 | + } | |
| 1753 | 1756 | |
| 1754 | - return $json_support; | |
| 1757 | + return version_compare((string) $wpdb->db_version(), '5.7.8', '>='); | |
| 1755 | 1758 | } |
| 1756 | 1759 | |
| 1757 | 1760 | /** |
| 1758 | 1761 | * Get SQL for the AI traffic table. |