Hello im writing a website and i want to make my custom function for selecting items from db but i cant solve my problem, anybody help?
function select($select, $from, $where, $item)
{
global $db;
if ($where != "")
{
$pdoselect = $db->prepare("select :select from :from where :where = :where2");
$pdoselect->bindParam(":select", $select);
$pdoselect->bindParam(":from", $from);
$pdoselect->bindParam(":where", $where);
$pdoselect->bindParam(":where2", $item);
$pdoselect->execute();
foreach ($pdoselect as $return)
{
echo $return[" . $select . "];
}
} else {
$pdoselect = $db->prepare("select :select from :from");
$pdoselect->bindParam(":select", $select);
$pdoselect->bindParam(":from", $from);
$pdoselect->execute();
foreach ($pdoselect as $return)
{
echo $return[" . $select . "];
}
}
}