在PDO中使用会话变量?转向PDO

时间:2013-06-20 15:12:21

标签: php mysql session variables pdo

所以我过去通过这样做来获得当前用户的权利:

 $dbQuery_ar = "SELECT * "; 

$dbQuery_ar .= "FROM users WHERE gebruikersnaam = ('$_SESSION[gebruikersnaam]')"; 
$result_ar = mysql_query($dbQuery_ar) or die("Couldn't get file list");
while($row = mysql_fetch_array($result_ar))
{

 $rechten = "$row[rechten]";      // get access level
 $_SESSION["rechten"] = "$rechten";      // make session variables 

}

有人可以告诉我如何编写包含会话用户名的pdo查询吗?

1 个答案:

答案 0 :(得分:0)

它实际上必须是什么

<?php
$stmt = $conn->prepare('SELECT rechten FROM users WHERE gebruikersnaam = ?');
$query->execute(array($_SESSION["gebruikersnaam"]));
$_SESSION["rechten"] = $query->fetchColumn();

另请参阅tag wiki了解正确的连接选项