connect_error) { header('Content-Type: application/json'); http_response_code(500); die(json_encode(['error' => 'Database connectie mislukt'])); } $db->set_charset('utf8mb4'); } return $db; } /** * Get WooCommerce database connection (WordPress/WooCommerce database) * Used for accessing plugin tables like wp_wdr_rules * @return mysqli */ function getWooCommerceDatabase(): mysqli { static $wcDb = null; if ($wcDb === null) { $wcDb = new mysqli( $_ENV['WC_DB_HOST'] ?? $_ENV['DB_HOST'], $_ENV['WC_DB_USER'] ?? $_ENV['DB_USER'], $_ENV['WC_DB_PASS'] ?? $_ENV['DB_PASS'], $_ENV['WC_DB_NAME'] ?? $_ENV['DB_NAME'] ); if ($wcDb->connect_error) { header('Content-Type: application/json'); http_response_code(500); die(json_encode(['error' => 'WooCommerce database connectie mislukt: ' . $wcDb->connect_error])); } $wcDb->set_charset('utf8mb4'); } return $wcDb; } /** * Get WooCommerce database table prefix * @return string */ function getWooCommerceDbPrefix(): string { return $_ENV['WC_DB_PREFIX'] ?? 'wp_'; } /** * Get WooCommerce client * @return Client */ function getWooCommerce(): Client { static $woocommerce = null; if ($woocommerce === null) { $woocommerce = new Client( $_ENV['WC_URL'], $_ENV['WC_KEY'], $_ENV['WC_SECRET'], ['version' => 'wc/v3', 'verify_ssl' => false] ); } return $woocommerce; }