Version 0.9.5 beta - Updated the MySQL adapter in order to load complete result sets by where selection.

This commit is contained in:
Stephan Kasdorf
2020-11-06 17:34:36 +01:00
parent 935575dfb3
commit 790f79530e
3 changed files with 82 additions and 17 deletions

View File

@@ -43,15 +43,6 @@ abstract class Db implements IDb
} }
} }
/**
* will return the last inserted id of the given table
* @return int
*/
public function lastInsertId()
{
return Pdo::getLastInsertedID();
}
/** /**
* @param bool $user_name * @param bool $user_name
* @return mixed * @return mixed
@@ -117,6 +108,24 @@ abstract class Db implements IDb
} }
} }
/**
* @param array $fieldWhere
* @return mixed|void
*/
public function selectDatasetByFieldWhere($fieldWhere = array())
{
return Pdo::selectDatasetByFieldAndValue(self::$table['table'], $fieldWhere);
}
/**
* will return the last inserted id of the given table
* @return int
*/
public function lastInsertId()
{
return Pdo::getLastInsertedID();
}
public function nextInsertIndex() public function nextInsertIndex()
{ {
// TODO: Implement nextInsertIndex() method. // TODO: Implement nextInsertIndex() method.

View File

@@ -11,12 +11,12 @@ namespace Nibiru;
final class Pdo extends Mysql implements IPdo final class Pdo extends Mysql implements IPdo
{ {
private static $section = false; private static $section = false;
public static function settingsSection( $section = IOdbc::SETTINGS_DATABASE ) public static function settingsSection( $section = IOdbc::SETTINGS_DATABASE )
{ {
self::$section = $section; self::$section = $section;
} }
private static function getSettingsSection() private static function getSettingsSection()
{ {
return self::$section; return self::$section;
@@ -57,7 +57,35 @@ final class Pdo extends Mysql implements IPdo
public static function selectDatasetByFieldAndValue($tablename = self::PLACE_TABLE_NAME, $fieldAndValue = array() ) public static function selectDatasetByFieldAndValue($tablename = self::PLACE_TABLE_NAME, $fieldAndValue = array() )
{ {
$result = parent::getInstance( self::getSettingsSection() )->getConn()->query("SELECT * FROM " . $tablename . " WHERE " . $fieldAndValue['name'] . " = '" . $fieldAndValue['value'] . "';"); $result = parent::getInstance( self::getSettingsSection() )->getConn()->query("SELECT * FROM " . $tablename . " WHERE " . $fieldAndValue['name'] . " = '" . $fieldAndValue['value'] . "';");
return $result->fetchAll(); $result = $result->fetchAll();
$resultset = [];
if(array_key_exists(0, $result))
{
foreach($result as $rowset)
{
$set = [];
foreach($rowset as $key=>$row)
{
if(!is_numeric($key))
{
$set[$key] = $row;
}
}
$resultset[] = $set;
}
}
else
{
foreach($result as $key=>$row)
{
if(!is_numeric($row))
{
$resultset[$key] = $row;
}
}
}
return $resultset;
} }
public static function updateColumnByFieldWhere( $tablename = self::PLACE_TABLE_NAME, public static function updateColumnByFieldWhere( $tablename = self::PLACE_TABLE_NAME,
@@ -121,14 +149,33 @@ final class Pdo extends Mysql implements IPdo
$prepare->execute(); $prepare->execute();
$r = $prepare->fetchAll(); $r = $prepare->fetchAll();
$rowset = array_shift( $r ); $rowset = array_shift( $r );
foreach(array_keys($rowset) as $entry) try{
{ if(is_array($rowset))
if(is_string($entry))
{ {
$result[$entry] = $rowset[$entry]; if(sizeof($rowset)>0)
{
foreach(array_keys($rowset) as $entry)
{
if(is_string($entry))
{
$result[$entry] = $rowset[$entry];
}
}
return $result;
}
}
else
{
return false;
} }
} }
return $result; catch (\Exception $e)
{
echo '<pre>';
print_r($e);
echo '</pre>';
die();
}
} }
/** /**

View File

@@ -29,6 +29,7 @@ interface IDb
* @return mixed * @return mixed
*/ */
public function loadTableAsArray(); public function loadTableAsArray();
/** /**
* @desc Has to select a given Rowset by the index ID of the table * @desc Has to select a given Rowset by the index ID of the table
* @param bool $id * @param bool $id
@@ -61,6 +62,14 @@ interface IDb
*/ */
public function insertArrayIntoTable( $dataset = array() ); public function insertArrayIntoTable( $dataset = array() );
/**
* @desc will return a result array from the searched where field from the database
* containing the entire dataset rows
* @param array $fieldWhere
* @return mixed
*/
public function selectDatasetByFieldWhere( $fieldWhere = array() );
/** /**
* @desc selects a row by the fieldname and the given value, should be * @desc selects a row by the fieldname and the given value, should be
* array('fieldname' => 'value') * array('fieldname' => 'value')