好吧,我一直在尝试查询mysql表中的视图,但是无论我做什么,都不会算错,如果我将确切的查询放在mysql直接上会触发,我不知道在做什么错,为了进一步解决问题,我将查询更改为来自另一个表的另一个视图,如果没有查看它的用法,请在下面的代码中找到:

$query4 = "select PageName FROM testpermission WHERE UserID='".$_SESSION['id']."' and PageName NOT LIKE '/%'";
$stmt2 = mysqli_stmt_init($conn);
mysqli_stmt_prepare($stmt2,$query4);
if( mysqli_stmt_execute($stmt2)){
die("i did it");
}
mysqli_stmt_bind_result($stmt2,$PageNAme);
 die("no i didnt");

最佳答案

也许您需要修剪UserID字段,请尝试以下操作:

$stmt = mysqli_prepare($conn, "select PageName FROM testpermission WHERE TRIM(UserID)= ? and PageName NOT LIKE '/%'");
mysqli_stmt_bind_param($stmt, "s", $_SESSION['id']);
if( mysqli_stmt_execute($stmt)){
    die("i did it");
} else {
    printf("Error: %s.\n", mysqli_stmt_error($stmt));
}

10-08 15:34