how to fetch single row with all columns in custom php function and return result
here is my custom function code
function getdata($sql,$dbh)
{
Let me suggest you to change this approach a bit, to make it A LOT more flexible.
So, change the code to this
function getdata($dbh, $sql, $params = NULL)
{
$stmt = $dbh->prepare($sql);
$stmt->execute($params)
return $stmt;
}
this way you'll be able to fetch either single record.
$row = getdata($dbh, $sql)->fetch();
or multiple rows
$row = getdata($dbh, $sql)->fetchAll();
or even run insert or update queries from which you cannot fetch at all.
You are not executing your Query?!
$dbh = new PDO("connection string");
$get_row = $dbh->prepare($sql);
$get_row->execute();
$row = $get_row->fetch();
Try this for get Single Row of all column.