使用PHP从函数中检索单个提取值

时间:2012-08-22 00:13:35

标签: php mysql function pdo session-variables

    //This is my function in retrieving the id of the user base from its email and pass. this is for functions.php 
       function getID($email,$pass)
        {
                $pdo = new PDO(connection here);
            $stmt = $pdo->prepare('SELECT id user where email = :email and pass = :pass LIMIT 1');
            $stmt->execute(array(':email'=>$email, ':pass'=>md5($pass)));
            $result = $stmt->fetch();
            return $result['id'];//Is this the right way of returning a value from a fetch value?
        }
//this is for user.php. 
include 'function.php';
session_start();
$_SESSION['id'] = getID($_POST['email'],$_POST['pass']);

这是检索它的正确方法吗?但我没有得到任何价值。需要帮助谢谢!

1 个答案:

答案 0 :(得分:0)

您的查询缺少FROM

SELECT id FROM user WHERE email = :email AND pass = :pass LIMIT 1