2

I am currently updating php code to use PDO. The legacy code is:

list($category_name,$parentid) = 
mysql_fetch_row(mysql_query(sprintf(" select name, parentid_fk from category 
where categoryid = '%s' ", mysql_escape($categoryid))));

I have so far updated it to:

$stmt = $db->prepare("select 
    name, parentid_fk
from 
    category
where 
    id = :categoryid
");
    $stmt->bindParam(":categoryid",$categoryid, PDO::PARAM_INT);
    $stmt->execute();   
    list($category_name,$parentid) = $stmt->fetch(PDO::FETCH_ASSOC);

When I echo $category_name or echo $parentid the values come out null. Can anyone tell me how to use the php list function with PDO?

Thanks

james q
  • 31
  • 2

1 Answers1

0

One way is using extract()

$result = $stmt->fetch(PDO::FETCH_ASSOC); // Get result

extract($result);  // Extract result
echo $name;        // Prints name value
echo $parentid_fk; // Prints parentid_fk value
Goma
  • 2,018
  • 1
  • 10
  • 19