Subsequent fixes after major changes for PDO
This commit is contained in:
37
lib.php
37
lib.php
@@ -31,6 +31,17 @@ $smarty->assign("suser_tooltips", $_SESSION['suser_tooltips'] ?? 'off');
|
||||
|
||||
// ========== DATABASE FUCTIONS ===============================================
|
||||
|
||||
function db_load_enum($table, $column) {
|
||||
// returns array of enum-values as defined in database
|
||||
global $dbh;
|
||||
$sql = "SELECT TRIM(TRAILING ')' FROM SUBSTRING(column_type,6))
|
||||
FROM information_schema.columns
|
||||
WHERE table_name=? AND column_name=?";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$table, $column]);
|
||||
return array_map(fn($x) => trim($x, "'"), explode(',', $sth->fetch(PDO::FETCH_NUM)));
|
||||
}
|
||||
|
||||
function db_get_options_asset() {
|
||||
global $dbh;
|
||||
$sql = "SELECT asset_id, asset_name FROM asset ORDER BY asset_name";
|
||||
@@ -61,8 +72,12 @@ function db_get_options_assetclassgroup() {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function db_get_options_location() {
|
||||
function db_get_options_location($default = NULL) {
|
||||
global $dbh;
|
||||
$options = array();
|
||||
if ($default != NULL) {
|
||||
$options[0] = $default;
|
||||
}
|
||||
$sql = "SELECT location_id, location_name FROM location ORDER BY location_name";
|
||||
$sth = $dbh->query($sql);
|
||||
foreach ($sth->fetchAll(PDO::FETCH_NUM) as $rec) {
|
||||
@@ -84,8 +99,12 @@ function db_get_options_subnet() {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function db_get_options_vlan() {
|
||||
function db_get_options_vlan($default = NULL) {
|
||||
global $dbh;
|
||||
$options = array();
|
||||
if ($default != NULL) {
|
||||
$options[0] = $default;
|
||||
}
|
||||
$sql = "SELECT vlan_id, vlan_name FROM vlan ORDER BY vlan_name";
|
||||
$sth = $dbh->query($sql);
|
||||
foreach ($sth->fetchAll(PDO::FETCH_NUM) as $rec) {
|
||||
@@ -94,4 +113,18 @@ function db_get_options_vlan() {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function db_get_options_zone($default = NULL) {
|
||||
global $dbh;
|
||||
$options = array();
|
||||
if ($default != NULL) {
|
||||
$options[0] = $default;
|
||||
}
|
||||
$sql = "SELECT zone_id, zone_origin FROM zone ORDER BY zone_origin";
|
||||
$sth = $dbh->query($sql);
|
||||
foreach ($sth->fetchAll(PDO::FETCH_NUM) as $rec) {
|
||||
$options[$rec[0]] = $rec[1];
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user