So i have the below function but for some reason when I use it in a page it does not return the assoc array. If i print_r on the array inside the function it prints out the array but when I call the function/array on a page it does not work. It's blank. Not sure what I am doing wrong.
function fetch_one($Table, $PK) {
include ("pdo_connection.php");
$sql = 'SELECT * FROM `'.$Table.'` WHERE PK = ? LIMIT 1';
//echo $sql;
$stmt = $db->prepare($sql);
$PK = (int)$PK;
$stmt->bindParam(1, $PK);
$stmt->execute();
$View = $stmt->fetch(PDO::FETCH_ASSOC);
return $View;
}
on the page itself i have
fetch_one($table, $pk);
print_r($View)
and it returns nothing.
When you run it you have to assign the value to a variable or else use it. Either
$x = fetch_one($table, $pk);
print_r($x);
or
print_r(fetch_one($table, $pk));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.