PDO返回1而不是返回db值
<?php
$dados = $conexao_pdo->prepare('SELECT name, surname, profile_description, verified FROM users WHERE username = ?');
$dados->bindParam(1, $user_logged);
$dados->execute();
if ($dados->rowCount() > 0) {
$campodb = $dados->fetch(PDO::FETCH_OBJ);
$user_logged_name = $campodb->name;
$user_logged_surname = $campodb->surname;
$user_logged_profile_description = $campodb->profile_description;
$user_logged_verified = $campodb->verified;
} else {
$user_logged_name = "";
$user_logged_surname = "";
$user_logged_profile_description = "";
$user_logged_verified = "";
}
?>
当我回显$user_logged_name
时,它向我返回1,而不是数据库中的用户名,为什么?
答案 0 :(得分:1)
您尝试了一段时间吗?
<?php
$dados = $conexao_pdo->prepare('SELECT name, surname, profile_description, verified FROM users WHERE username = ?');
$dados->bindParam(1, $user_logged);
$dados->execute();
if ($dados->rowCount() > 0) {
//$campodb = $dados->fetch(PDO::FETCH_OBJ);
while ($campodb = $dados->fetch(PDO::FETCH_OBJ)) {
$user_logged_name = $campodb->name;
$user_logged_surname = $campodb->surname;
$user_logged_profile_description = $campodb->profile_description;
$user_logged_verified = $campodb->verified;
}
} else {
$user_logged_name = "";
$user_logged_surname = "";
$user_logged_profile_description = "";
$user_logged_verified = "";
}
?>