没有从MySQL获取数据 - PHP

时间:2013-05-16 17:43:32

标签: php mysql variables

我将从代码开始:

$permission = $_SESSION['permission'];
// Connect to database
$con = new mysqli("localhost", "privateinfo", "privateinfo", "privateinfo");

// Check connection
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

// Prepare to select all liabilities
$stmt = $con->prepare("SELECT `Linking`, `Edit_Liab`, `Own_Stud`, `All_Stud`, `View_Report`, `Read_Write` FROM Permissions WHERE `ID`=?");
$stmt->bind_param("s", $permission);  // Bind variables to the result of the query
$stmt->execute(); // Execute the query
$stmt->bind_result($linking, $editliab, $ownstud, $allstud, $viewrep, $readwrite); // Bind variables to the result of the query
$stmt->store_result();
$stmt->close();

基本上,我的问题是php没有得到任何变量。所有变量都应该是1,但它们实际上都是零。连接很好,我尝试将die语句放在几乎所有的东西上都会出现错误,但没有任何结果。进入的权限变量也正确设置。将它直接放在SQL代码中也可以得到正确的响应。我不太确定这里有什么问题。有人有任何想法吗?

1 个答案:

答案 0 :(得分:0)

您需要fetch a row而不是storing the result

所以改变:

$stmt->store_result();

为:

$stmt->fetch();