我有两个递归函数:
1)
function getCategories($id)
{
global $con;
$select = $con->prepare('SELECT * FROM categories WHERE parent_category_id = :parent_category_id OR (parent_category_id IS NULL AND :parent_category_id IS NULL)');
$select->bindValue(':parent_category_id', $id, PDO::PARAM_NULL || PDO::PARAM_INT);
$select->execute();
// fetching.........
for() ... getCategories(.......);
}
2)
$select = $con->prepare('SELECT * FROM categories WHERE parent_category_id = :parent_category_id OR (parent_category_id IS NULL AND :parent_category_id IS NULL)');
function getCategories($id)
{
global $select;
$select->bindValue(':parent_category_id', $id, PDO::PARAM_NULL || PDO::PARAM_INT);
$select->execute();
// fetching.........
for() ... getCategories(.......);
}
哪个更好/更快?只准备一次声明会更好吗?