Hello All,
public static function whereHelper($whereClause)
{
$strData = 'WHERE ';
$tempNum = 0;
foreach($whereClause as $key => $value)
{
if ( $tempNum == 1){
$strData = $strData . ' ' . "AND" . $key . "=" . $value;
}
else
{
$strData = $strData . ' ' . $key . "=" . $value;
$tempNum = 1;
}
}
return $strData;
}
public static function statementHelper($value)
{
$tempStore = "";
$tempNum = 0;
foreach($value as $statementValue)
{
if($tempNum == 0 )
{
$tempStore = $statementValue;
$tempNum = 1;
}
else
{
$tempStore = $tempStore . ' , ' . $statementValue;
}
}
return $tempStore;
}
public static function selectStatement($arrayValueClause)
{
$fieldStatement = "*";
$whereStatement = "";
foreach($arrayValueClause as $key => $value)
{
if ($key == "statement")
{
$fieldStatement = self::statementHelper($value);
}
if ($key == "where")
{
$whereStatment = self::whereHelper($value);
}
}
return self::executeSelect('SELECT ' .$fieldStatement. ' FROM '. self::$table . ' '. $whereStatment);
}
public static function update($colValueArray, $whereClause)
{
}
public static function executeSelect($sql)
{
//return whereHelper();
try
{
//$dhn = new PDO(self::$dsn, self::$user, self::$password);
//print_r($data_array);
self::$dhn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$tmt = self::$dhn->prepare($sql);
$tmt->execute((array)self::$data_array);
$row = $tmt->fetchAll(PDO::FETCH_ASSOC);
return $row;
}
catch(PDOException $e)
{
echo 'Connection failed: ' . $e->getMessage();
}
}
The above code works but I would like to improve on it. Please review it and comment.
Regards,
Janus