Hi
I get the following code that use pdo connection code.
I want to call "function getHolidayFTag($date, $kanton, $pdo)" from Row_Rendered or Row_Inserted server event.
In this script is database, username etc is given.
How can I integrate this script into phpmaker 2024 to call the defined functions in it?
// Database connection details
$dsn = 'mysql:host=localhost;dbname=ttracker;charset=utf8';
$username = 'Gers***';
$password = '*********';
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
try {
// Establish PDO connection
$pdo = new PDO($dsn, $username, $password, $options);
} catch (PDOException $e) {
// Handle connection error
die("Error: " . $e->getMessage());
}
// Function to check if a date is a holiday in a specific Kanton and get FTag
function getHolidayFTag($date, $kanton, $pdo) {
$stmt = $pdo->prepare("SELECT FTag FROM feiertage WHERE Datum = ? AND Nummer = ?");
$stmt->execute([$date, $kanton]);
$result = $stmt->fetch();
return $result ? $result['FTag'] : 0;
}
........
mpol_ch