From 94b626eb3677106cc948d39527f920a42c6d0d72 Mon Sep 17 00:00:00 2001 From: Stephan Kasdorf Date: Mon, 6 Jan 2020 12:47:04 +0100 Subject: [PATCH] Version 0.9.5 beta - minor bugfix for selecting datasets by primary key id, now is working with the abstract layer and the PDO adapter. --- core/a/mysql.db.php | 2 +- core/c/pdo.php | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/core/a/mysql.db.php b/core/a/mysql.db.php index 702e304..b6e3b44 100644 --- a/core/a/mysql.db.php +++ b/core/a/mysql.db.php @@ -68,7 +68,7 @@ abstract class Db implements IDb */ public function selectRowsetById($id = false) { - // TODO: Implement selectRowsetById() method. + return Pdo::fetchRowInArrayById( self::getTable()['table'], $id ); } /** diff --git a/core/c/pdo.php b/core/c/pdo.php index fa55770..c7d70f6 100644 --- a/core/c/pdo.php +++ b/core/c/pdo.php @@ -89,7 +89,8 @@ final class Pdo extends Mysql implements IPdo } } $prepare = $statement->prepare("SELECT * FROM " . $tablename . " WHERE " . $id_name . " = :" . $id_name . ";"); - $prepare->execute($id); + $prepare->bindParam(":".$id_name, $id, \PDO::PARAM_INT); + $prepare->execute(); $fetchAll = $prepare->fetchAll(); $rowset = array_shift($fetchAll); @@ -130,6 +131,36 @@ final class Pdo extends Mysql implements IPdo return $result; } + /** + * @desc selects the given table row by given parameter and column + * @param string $tablename + * @param string $column_name + * @param string $parameter_name + * @return mixed + */ + public static function fetchRowsInArrayByWhere($tablename = IMysql::PLACE_TABLE_NAME, + $column_name = IMysql::PLACE_COLUMN_NAME, + $parameter_name = IMysql::PLACE_SEARCH_TERM) + { + $statement = parent::getInstance( self::getSettingsSection() )->getConn(); + $result = []; + $prepare = $statement->prepare("SELECT * FROM " . $tablename . " WHERE " . $column_name . " = :" . $column_name . ";"); + $prepare->bindParam(":".$column_name, $parameter_name, \PDO::PARAM_STR); + $prepare->execute(); + $r = $prepare->fetchAll(); + foreach($r as $key=>$item) + { + foreach ($item as $index=>$field) + { + if(!is_numeric($index)) + { + $result[$key][$index] = $field; + } + } + } + return $result; + } + public static function getLastInsertedID() { // TODO: Implement getLastInsertedID() method.