运行时如果mysql上的函数结果出错

时间:2017-07-06 08:18:31

标签: php mysqli

我试图在MySQL表中设置权限,但我收到错误:

Warning: mysqli::query() expects parameter 1 to be string, object given in 
/public/sites/staffpaneel.mc-wonderland.nl/index.php on line 656

Catchable fatal error: Object of class mysqli_result could not be converted 
to string in /public/sites/staffpaneel.mc-wonderland.nl/index.php on line 679

有没有人为我解决这个问题,我已经尝试了很多东西,但没有任何效果

    <?php
    //Perms
    $PermissiesUitlezen = mysqli_query($conn, "SELECT * FROM `RankPermissies` WHERE RankID ° '".$sqlDataIngelogd['RankID']."'");
    $sqlDataPermissies = mysqli_fetch_assoc($PermissiesUitlezen);

if ($conn->query($PermissiesUitlezen) === TRUE) {
    if ($sqlDataPermissies['AccountMakenMag'] == 1) {
        AccountMakenMag();
    }
    if ($sqlDataPermissies['AccountsMag'] == 1) {
        AccountsMag();
    }
    if ($sqlDataPermissies['MeldingMakenMag'] == 1) {
        MeldingMakenMag();
    }
    if ($sqlDataPermissies['RankAanmakenMag'] == 1) {
        RankAanmakenMag();
    }
    if ($sqlDataPermissies['RanksMag'] == 1) {
        RanksMag();
    }
    if ($sqlDataPermissies['StoringMakenMag'] == 1) {
        StoringMakenMag();
    }
    if ($sqlDataPermissies['StoringenMag'] == 1) {
        StoringenMag();
    }
} else {
    echo "Fout: " . $PermissiesUitlezen . "<br>" . $conn->error;
}
    ?>

2 个答案:

答案 0 :(得分:0)

可以从

更改您的查询吗?
SELECT * FROM `RankPermissies` WHERE RankID ° '".$sqlDataIngelogd['RankID']."'

SELECT * FROM `RankPermissies` WHERE RankID = '".$sqlDataIngelogd['RankID']."'

然后检查。

答案 1 :(得分:0)

问题在于$PermissiesUitlezen保留了mysqli_query()来电的结果,而在if中您将其用作另一个mysqli_query()来电的参数。这没有任何意义。

实际上,如果您在php.net上阅读mysqli_query()上的手册,您就会知道如何正确检查错误:

 if ($PermissiesUitlezen = mysqli_query($conn, "SELECT * FROM `RankPermissies` WHERE RankID = '".$sqlDataIngelogd['RankID']."'")) {
     $sqlDataPermissies = mysqli_fetch_assoc($PermissiesUitlezen);
     ...

请注意,我还更正了sql语句(将°替换为=。但请注意,如果在sql查询中有参数,则应使用预准备语句。