As I have to fetch data multiple times so I created select function and where function is it write way to way to use and also in point of view of SQL Injection , this way is not good ? Please guide
function where($column, $value) {
return "AND $column = :$column";
}
function fetchCategory($where, $data1) {
// Create a PDO instance
$db = Database::newInstance();
// Build the SELECT statement with a WHERE clause
$sql1 = "SELECT * FROM category WHERE 1=1 $where";
// Execute the SELECT statement with bound parameters
$row1 = $db->read($sql1, $data1);
// Return the result set
return $row1;
}
$where = where('cat_id', $value->parent_id);
$data1 = array(':cat_id' => $value->parent_id);
$result = fetchCategory($where, $data1);
if ($result) {
// Fetch the data from the result set
$data['Dis_05']= $result[0]->category;
} else {
// No data was found
echo "No data found";
}