这不是在带有MySQL的php中返回user_id

时间:2015-07-06 10:29:41

标签: php pdo

try{
    $query = "SELECT user_id FROM user WHERE username = '".$username."'";

    $result = $dbhandle->query($query,PDO::FETCH_OBJ);
    //$stmt->bindParam(":username",$username);

//  $result = $stmt->fetchAll(PDO::FETCH_BOTH);


                while($row = $result->fetch()){

                    $id = $row['user_id'];


                    $_SESSION['user_id'] = $id;

                    }

                }catch(PDOException $e){ echo $e->getMessage();}

1 个答案:

答案 0 :(得分:0)

您可以将此代码用作示例代码

   protected $middleware = [
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
    \App\Http\Middleware\EncryptCookies::class,
    \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
    \Illuminate\Session\Middleware\StartSession::class,
    \Illuminate\View\Middleware\ShareErrorsFromSession::class,
    \App\Http\Middleware\VerifyCsrfToken::class,
    \JacobBennett\Pjax\PjaxMiddleware::class
];

希望这有帮助。