2017-08-08 53 views
0

爲什麼fetchColumn()在數據庫中實際存在兩列符合這些條件時會返回「1」?爲什麼fetchColumn()在有2列時返回1?

如果數據庫中有1條記錄匹配,它將返回false? (我以前做$num_of_rows = $stmt->num_rows()它完美地工作)

$follower = 1; 
$following = 1; 

$stmt = $dbCon->prepare(" SELECT login_followers_status " 
     . " FROM login_followers " 
     . " WHERE login_followers_follower = ? " 
     . " AND login_followers_following = ? "); 
$stmt->bindParam(1, $follower); 
$stmt->bindParam(2, $following); 
$stmt->execute(); 
$row = $stmt->fetch(); 
$status = $row['login_followers_status']; 
$num_of_rows = $stmt->fetchColumn(); 

echo $num_of_rows; 

回答

0

爲什麼你不看手冊?

public mixed PDOStatement::fetchColumn ([ int $column_number = 0 ])

PDOStatement對象:: fetchColumn - 從返回的結果集的下一行 一列。

返回結果集的下一行中的單個列,如果 沒有更多行,則返回FALSE。

警告如果您使用PDOStatement :: fetchColumn()檢索數據,則無法從同一行返回另一列。