From 91a8c4e5674900ce2f0f2e32458527e62259ca29 Mon Sep 17 00:00:00 2001 From: Walter Hupfeld Date: Sat, 17 Feb 2024 08:42:54 +0100 Subject: [PATCH] PDO --- admin/dump.php | 4 ++-- admin/index.php | 10 +++++----- admin/login.php | 2 +- admin/print_html.php | 6 +++--- admin/shapefile.php | 2 +- ajax/ajax_location_push.php | 5 +++-- config.db.php | 12 ++++++++++++ config.php | 11 +++-------- index.php | 9 +++++---- lib/functions.php | 2 +- lib/geocoding.php | 4 ++-- liste.php | 4 ++-- setup.php | 26 -------------------------- setup_chk.php | 4 ++-- 14 files changed, 42 insertions(+), 59 deletions(-) create mode 100644 config.db.php diff --git a/admin/dump.php b/admin/dump.php index abd582d..8da3289 100644 --- a/admin/dump.php +++ b/admin/dump.php @@ -30,7 +30,7 @@ $query = $db->query($strSQL); // Fetch the first row - $row = $query->fetchArray(SQLITE3_ASSOC); + $row = $query->fetch(PDO::FETCH_ASSOC); // If no results are found, echo a message and stop if ($row == false){ @@ -49,7 +49,7 @@ echo $line . "\n"; // Fetch the next line - $row = $query->fetchArray(SQLITE3_ASSOC); + $row = $query->fetch(PDO::FETCH_ASSOC); } // Prints the column names diff --git a/admin/index.php b/admin/index.php index 0bbf667..f186791 100644 --- a/admin/index.php +++ b/admin/index.php @@ -37,7 +37,7 @@ $stmt = $db->prepare("SELECT * FROM files where loc_id = :loc_id"); $stmt->bindValue(":loc_id", $numDelete, SQLITE3_TEXT); $result = $stmt->execute(); - if ($row = $result->fetchArray()) { + if ($row = $result->fetch(PDO::FETCH_ASSOC)) { $strFilename = $row['filename']; $strFilename = $uploaddir . $strFilename; unset($strFilename); @@ -67,7 +67,7 @@ $stmt = $db->prepare("SELECT * FROM files where id = :id"); $stmt->bindValue(":id", $numDelete, SQLITE3_TEXT); $result = $stmt->execute(); - if ($row=$result->fetchArray()) { + if ($row=$result->fetch(PDO::FETCH_ASSOC)) { $strFilename = $row['filename']; $strFilename = $uploaddir . $strFilename; unset($strFilename); @@ -181,7 +181,7 @@ //$strSQL="SELECT * FROM location ORDER BY created_at DESC"; $strSQL="SELECT l.id as lid,l.*,adr.* FROM location l LEFT JOIN address adr ON l.id=adr.loc_id ORDER BY created_at ASC"; $result = $db->query($strSQL); - while ($row = $result->fetchArray()) { + while ($row = $result->fetch(PDO::FETCH_ASSOC)) { $id = $row['lid']; echo ""; echo "".$id.""; @@ -194,7 +194,7 @@ echo ""; $strSQL = "SELECT id,username,comment,created_at FROM comment WHERE loc_id=".$id; $comments = $db->query($strSQL); - while ($comment = $comments->fetchArray()) { + while ($comment = $comments->fetch(PDO::FETCH_ASSOC)) { echo "
"; echo "".$comment['username']." schrieb am "; $numDatum = strtotime($comment['created_at']); @@ -215,7 +215,7 @@ echo ""; $strSQL = "SELECT id,filename FROM files WHERE loc_id=".$id; $files=$db->query($strSQL); - if ($file=$files->fetchArray()) { + if ($file=$files->fetch(PDO::FETCH_ASSOC)) { echo ""; echo ""; echo ""; diff --git a/admin/login.php b/admin/login.php index 75f2b31..4f1d0d5 100644 --- a/admin/login.php +++ b/admin/login.php @@ -20,7 +20,7 @@ $boolLogin=true; $strPassword = trim($_POST['password']); $strSQL = "SELECT username,passwordhash FROM user WHERE username='$strUser'"; $result = $db->query($strSQL); - if ($row=$result->fetchArray()) { + if ($row=$result->fetch(PDO::FETCH_ASSOC)) { if (password_verify($strPassword,$row['passwordhash'])) { session_start(); $_SESSION['user']=$strUser; diff --git a/admin/print_html.php b/admin/print_html.php index d87f3f0..4b00d86 100644 --- a/admin/print_html.php +++ b/admin/print_html.php @@ -72,7 +72,7 @@ $strScript=""; $strSQL="SELECT l.id as lid,l.*,adr.* FROM location l LEFT JOIN address adr ON l.id=adr.loc_id ORDER BY city,postcode,suburb,hamlet,road ASC"; $result = $db->query($strSQL); - while ($row = $result->fetchArray()) { + while ($row = $result->fetch(PDO::FETCH_ASSOC)) { $id = $row['lid']; $numDatum= strtotime($row['created_at']); $strDatum= date("d.m.Y",$numDatum); @@ -86,7 +86,7 @@ echo ""; $strSQL = "SELECT id,username,comment,created_at FROM comment WHERE loc_id=".$id; $comments = $db->query($strSQL); - while ($comment = $comments->fetchArray()) { + while ($comment = $comments->fetch(PDO::FETCH_ASSOC)) { echo "
"; echo "".$comment['username']." schrieb am "; $numDatum = strtotime($comment['created_at']); @@ -102,7 +102,7 @@ echo ""; $strSQL = "SELECT id,filename FROM files WHERE loc_id=".$id; $files=$db->query($strSQL); - if ($file=$files->fetchArray()) { + if ($file=$files->fetch(PDO::FETCH_ASSOC)) { echo ""; } echo ""; diff --git a/admin/shapefile.php b/admin/shapefile.php index cffaa55..7a81ff9 100644 --- a/admin/shapefile.php +++ b/admin/shapefile.php @@ -11,7 +11,7 @@ $result = $db->query("SELECT * FROM location ORDER BY created_at ASC"); $coords_array = array (); -while ($row = $result->fetchArray(SQLITE3_ASSOC)) { +while ($row = $result->fetch(PDO::FETCH_ASSOC)) { $coords_array[]=$row; } diff --git a/ajax/ajax_location_push.php b/ajax/ajax_location_push.php index adf35de..8d1639f 100644 --- a/ajax/ajax_location_push.php +++ b/ajax/ajax_location_push.php @@ -1,6 +1,7 @@ execute(); // fetch last_id - sqlite $strSQL="SELECT id FROM location ORDER BY id DESC limit 1"; $result = $db->query($strSQL); -if ($row = $result->fetchArray()) { +if ($row = $result->fetch(PDO::FETCH_ASSOC)) { $id = $row['id']; } @@ -79,7 +80,7 @@ if ($boolUploadOk) { // Retrun Markertext of entry $strSQL="SELECT loc.*,f.filename FROM location loc LEFT JOIN files f ON loc.id=f.loc_id ORDER BY loc.id DESC limit 1"; $result = $db->query($strSQL); -if ($row = $result->fetchArray()) { +if ($row = $result->fetch(PDO::FETCH_ASSOC)) { $markerText=generate_tooltip_description($row); $markerText=stripcslashes($markerText); } diff --git a/config.db.php b/config.db.php new file mode 100644 index 0000000..27e9d28 --- /dev/null +++ b/config.db.php @@ -0,0 +1,12 @@ +getMessage(); die();} diff --git a/config.php b/config.php index 1eab480..e3321c0 100644 --- a/config.php +++ b/config.php @@ -8,17 +8,12 @@ * Datum: 18.05.2021 ******************************** */ - - date_default_timezone_set('UTC'); - if (!isset($dbFilename)) { - $dbFilename = "db/locations.db"; - } - $db = new SQLite3($dbFilename); + require_once("config.db.php"); - $strSQL="select * from config"; + $strSQL = "select * from config"; $result = $db->query($strSQL); - while ($row = $result->fetchArray(SQLITE3_ASSOC)) { + while ($row = $result->fetch(PDO::FETCH_ASSOC)) { switch ($row['key']) { case "uploaddir" : $uploaddir=$row['value']; diff --git a/index.php b/index.php index baec4ab..d946ad1 100644 --- a/index.php +++ b/index.php @@ -4,15 +4,16 @@ * Ideenmelder * Autor: Walter Hupfeld, Hamm * E-Mail: info@hupfeld-software.de - * Version: 1.0 - * Datum: 18.05.2021 + * Version: 2.0 + * Datum: 16.02.2024 ******************************** */ if (!file_exists("db/locations.db")) { header("Location: setup.php"); } - require("config.php"); + require("config.db.php"); + require("config.php"); require_once("lib/functions.php"); $ref=(isset($_GET['ref']) && ($_GET['ref']==1)); @@ -32,7 +33,7 @@ $arrMarker = array(); $arrDescription = array(); - while ($row = $result->fetchArray()) { + while ($row = $result->fetch(PDO::FETCH_ASSOC)) { $id=$row['id']; $topic = $row['topic']; $numLng = $row['lng']; diff --git a/lib/functions.php b/lib/functions.php index 59fc2bf..c28953f 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -56,7 +56,7 @@ function generate_tooltip_description($row) { $strSQL = "SELECT username,comment,created_at FROM comment WHERE loc_id=".$id; $result = $db->query($strSQL); - while ($comment = $result->fetchArray()) { + while ($comment = $result->fetch(PDO::FETCH_ASSOC)) { $strDescription .= "
"; $strDescription .= "".$comment['username']." schrieb am "; $numDatum = strtotime($comment['created_at']); diff --git a/lib/geocoding.php b/lib/geocoding.php index ea8ddbb..1371a29 100644 --- a/lib/geocoding.php +++ b/lib/geocoding.php @@ -79,7 +79,7 @@ function fillAddressTable($db,$limit=20) { // Get all ids from address table and write to array $strSQL="select loc_id from address"; $result=$db->query($strSQL); - while ($row=$result->fetchArray()) { + while ($row=$result->fetch(PDO::FETCH_ASSOC)) { $arrIds[]=$row['loc_id']; } @@ -95,7 +95,7 @@ function fillAddressTable($db,$limit=20) { $strTable .= "".$key.""; } $strTable .= ""; - while ($row=$result->fetchArray()) { + while ($row=$result->fetch(PDO::FETCH_ASSOC)) { $id=$row['id']; if (!in_array($id,$arrIds) && $counter<$limit) { $counter++; diff --git a/liste.php b/liste.php index da3a084..2ba2901 100644 --- a/liste.php +++ b/liste.php @@ -107,7 +107,7 @@ $strSQL="SELECT loc.*,f.filename FROM location loc LEFT JOIN files f ON loc.id=f.loc_id ORDER BY created_at DESC"; $result = $db->query($strSQL); $numCounter=1; - while ($row = $result->fetchArray()) { + while ($row = $result->fetch(PDO::FETCH_ASSOC)) { $numDatum= strtotime($row['created_at']); $id=$row['id']; $datum= date("d.m.Y",$numDatum); @@ -126,7 +126,7 @@ echo ""; $strSQL = "SELECT username,comment,created_at FROM comment WHERE loc_id=".$id; $comments = $db->query($strSQL); - while ($comment = $comments->fetchArray()) { + while ($comment = $comments->fetch(PDO::FETCH_ASSOC)) { echo "
"; echo "".$comment['username']." schrieb am "; $numDatum = strtotime($comment['created_at']); diff --git a/setup.php b/setup.php index 4e47688..1ed0bc2 100644 --- a/setup.php +++ b/setup.php @@ -71,33 +71,7 @@ } ?> -
  • -Datenbankverzeichnis konnte nicht angelegt werden."; - $boolError=true; - } - } -} -?> -
  • query("TRUNCATE config"); $boolActive = (isset($_POST['active'])) ? "1" : "0"; $boolRating = (isset($_POST['rating'])) ? "1" : "0";