science-ation/helper.inc.php
2024-12-17 01:34:35 -05:00

30 lines
802 B
PHP

<?
function get_value_from_session(string $key, mixed $default = null) : mixed
{
return isset($_SESSION[$key]) ? $_SESSION[$key] : $default;
}
function get_value_from_array(array $ar, string $key, mixed $default = null) : mixed
{
return isset($ar[$key]) ? $ar[$key] : $default;
}
function get_value(mixed $var) : mixed
{
return isset($var) ? $var : null;
}
function get_value_or_default(mixed $var, mixed $default = null) : mixed {
return isset($var) ? $var : $default;
}
function show_pdo_errors_if_any($pdo) {// Check for errors after the query execution
$errorInfo = $pdo->errorInfo();
if ($errorInfo[0] != '00000') {
// If there's an error (the SQLSTATE isn't '00000', which means no error)
echo "Error: " . $errorInfo[2]; // The third element contains the error message
}
}
?>