2014-04-13 34 views
0

我試圖將我的變量綁定到一個數組中。目前,我有他們在他們自己的陣列。我需要做些什麼來將它們綁定到一個數組中?PHP準備語句將多個變量綁定到一個數組

$catSelect = $db->prepare("SELECT... WHERE jos_categories.alias = ?"); 
$catSelect->bind_param('s', $category); 
$catSelect->execute(); 
$catSelect->bind_result($contentAlias, $contentCatID, $contentTitle, $contentID); 

$contentAliasArray = array(); 
$contentCatIDArray = array(); 
$contentTitleArray = array(); 
$contentIDArrray = array(); 

while ($catSelect->fetch()) { 
    $contentAliasArray[]=$contentAlias; 
    $contentCatIDArray[] = $contentCatID; 
    $contentTitleArray[] = $contentTitle; 
    $contentIDArrray[] = $contentID; 
} 

$catSelect->close(); 

回答

0
$stmt = $db->prepare("SELECT... WHERE jos_categories.alias = ?"); 
$stmt->bind_param('s', $category); 
$stmt->execute(); 
$res = $stmt->get_result(); 
$array = $res->fetch_all(); 

另一種方式是交換的mysqli爲PDO

$stmt = $pdo->prepare("SELECT... WHERE jos_categories.alias = ?"); 
$stmt->execute([$category]); 
$array = $res->fetchAll(); 
相關問題