2026-01-10 15:30:05 +01:00

55 lines
1.1 KiB
PHP

<?php
/**
* Configuration file - Database connection and WooCommerce client
*/
use Automattic\WooCommerce\Client;
/**
* Get database connection
* @return mysqli
*/
function getDatabase(): mysqli
{
static $db = null;
if ($db === null) {
$db = new mysqli(
$_ENV['DB_HOST'],
$_ENV['DB_USER'],
$_ENV['DB_PASS'],
$_ENV['DB_NAME']
);
if ($db->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 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;
}