Version 0.9.5 beta - Updated the MySQL adapter in order to load complete result sets by where selection.
This commit is contained in:
@@ -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
|
||||
* @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()
|
||||
{
|
||||
// TODO: Implement nextInsertIndex() method.
|
||||
|
||||
@@ -11,12 +11,12 @@ namespace Nibiru;
|
||||
final class Pdo extends Mysql implements IPdo
|
||||
{
|
||||
private static $section = false;
|
||||
|
||||
|
||||
public static function settingsSection( $section = IOdbc::SETTINGS_DATABASE )
|
||||
{
|
||||
self::$section = $section;
|
||||
}
|
||||
|
||||
|
||||
private static function getSettingsSection()
|
||||
{
|
||||
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() )
|
||||
{
|
||||
$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,
|
||||
@@ -121,14 +149,33 @@ final class Pdo extends Mysql implements IPdo
|
||||
$prepare->execute();
|
||||
$r = $prepare->fetchAll();
|
||||
$rowset = array_shift( $r );
|
||||
foreach(array_keys($rowset) as $entry)
|
||||
{
|
||||
if(is_string($entry))
|
||||
try{
|
||||
if(is_array($rowset))
|
||||
{
|
||||
$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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,6 +29,7 @@ interface IDb
|
||||
* @return mixed
|
||||
*/
|
||||
public function loadTableAsArray();
|
||||
|
||||
/**
|
||||
* @desc Has to select a given Rowset by the index ID of the table
|
||||
* @param bool $id
|
||||
@@ -61,6 +62,14 @@ interface IDb
|
||||
*/
|
||||
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
|
||||
* array('fieldname' => 'value')
|
||||
|
||||
Reference in New Issue
Block a user