此功能有效:
function son_bolum_liste_cek($limit)
{
global $db;
$query = $db->prepare("SELECT `anime_bolum`.`id`, `anime`.`isim`, `anime_bolum`.`bolum_no`, `image`.`url` as `image`, `gifimage`.`url` as `gifimage` FROM `anime_bolum` JOIN `anime` ON `anime`.`id` = `anime_bolum`.`anime_id` JOIN `image` ON `anime_bolum`.`image` = `image`.`id` JOIN `image` as `gifimage` ON `gifimage`.`id` = `anime_bolum`.`gifimage` ORDER BY `anime_bolum`.`id` DESC LIMIT :limit;");
$query->bindValue(':limit', $limit, PDO::PARAM_INT);
$select = $query->execute();
return $query->fetchAll();
}
foreach (son_bolum_liste_cek(12) as $anime){blabla};
但这不是工作:
function db_toplu_veri_oku($query, $execute = array() , $binds = array(),$debug = false)
{
global $db;
$query = $db->prepare($query);
foreach($binds as $bind)
{
$query->bindValue($bind[0], $bind[1], $bind[2]);
}
$select = $query->execute($execute);
if($debug){$query->debugDumpParams();};
return $query->fetchAll();
}
function son_bolum_liste_cek($limit)
{
$query = "SELECT `anime_bolum`.`id`, `anime`.`isim`, `anime_bolum`.`bolum_no`, `image`.`url` as `image`, `gifimage`.`url` as `gifimage` FROM `anime_bolum` JOIN `anime` ON `anime`.`id` = `anime_bolum`.`anime_id` JOIN `image` ON `anime_bolum`.`image` = `image`.`id` JOIN `image` as `gifimage` ON `gifimage`.`id` = `anime_bolum`.`gifimage` ORDER BY `anime_bolum`.`id` DESC LIMIT :limit;";
$binds = array(array(':limit',$limit,PDO::PARAM_INT));
return db_toplu_veri_oku($query,array(),$binds);
}
foreach (son_bolum_liste_cek(12) as $anime){blabla};
两个功能做同样的工作,但底层功能不起作用为什么?我在哪里做错了?
答案 0 :(得分:0)
变化不大。 execute
中的问题。你正在传递空白数组。因此,您必须首先检查数组是否包含值
function db_toplu_veri_oku($query, $execute = array() , $binds = array(),$debug = false)
{
global $db;
$query = $db->prepare($query);
foreach($binds as $bind)
{
$query->bindValue($bind[0], $bind[1], $bind[2]);
}
if(count($execute)) //<-----------Add this condition
$select = $query->execute($execute);
else
$select = $query->execute();
if($debug){$query->debugDumpParams();};
return $query->fetchAll();
}