不会从php

时间:2017-02-01 08:00:16

标签: php mysql view

我一直在尝试查询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");

2 个答案:

答案 0 :(得分:2)

也许你需要修剪你的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));
}

答案 1 :(得分:0)

谢谢大家,

好吧,似乎mysql中的视图存在错误,所以我直接将其更改为查询

[code]选择0 12 * * * python3 /home/ec2-user/example.pytblpermissions AS PageName来自(Pagename加入tblpermissions on(tbluserpermissions。{{1} } = tblpermissionsPermissionID)))其中userid ='“。$ _ SESSION ['id']。”'和PageName NOT LIKE'/%'[code]