如何使用此代码获取user_id

时间:2014-03-28 14:07:18

标签: php mysql sql

我这里有这个代码:

$selectUserQuery = 'SELECT user_id, email_address, password FROM user WHERE email_address = :email_address AND password = :password AND confirm_status = 1';
$prepSelectUser = $conn->prepare($selectUserQuery);
$prepSelectUser->bindParam(':email_address', $emailEnc, PDO::PARAM_STR);
$prepSelectUser->bindParam(':password', $passwordEnc, PDO::PARAM_STR);
$prepSelectUser->execute();
$userResult = $prepSelectUser->fetchAll();
$userCount = count($userResult);

我选择电子邮件地址和密码以查看它们是否匹配(这是用于登录),我需要user_id以user_id作为其值启动会话。但是,fetchAll()函数返回结果数组,但我需要单独使用user_id,只能将其用作会话的值。

如何单独获取user_id?

2 个答案:

答案 0 :(得分:0)

试试这个:

foreach ( $userResult AS $row ) {
    var_dump($row[0]);
}

答案 1 :(得分:0)

它应该在Userresult ::

中 通常你应该是:

$userResult[0]['user_id'] (1st user)
$userResult[1]['user_id'] 2th user
$userResult[5]['user_id'] 6th user....