简体   繁体   English

MySQLi查询在Webspace上不起作用

[英]mysqli query doesn't work at webspace

Im using mysqli on my localhost it works just fine, but when i upload it to my web server, the page just gets white and nothing else happens.Now i am here to ask for help if you can check on this only function i have in "functions.php" if i remove this function the page loads and if i add it back, the page gets white. 我在我的本地主机上使用mysqli可以正常工作,但是当我将其上传到Web服务器时,页面变得白了,什么也没发生。现在我在这里寻求帮助,如果您可以检查一下我拥有的唯一功能如果删除了该功能,则“ functions.php”页面会加载,如果我将其重新添加,页面会变白。

function getUserName($userID) { 
        global $mysqli; 
        $userID = $mysqli->real_escape_string($userID);
        $sql = $mysqli->query("SELECT * FROM users WHERE userID='".$userID."' LIMIT 1"); 
        if ($sql->num_rows > 0) { return $sql->fetch_assoc()['username']; }
        else { return 0; }
    }

And in the index.php i have the connection before this row. 在index.php中,我在此行之前有连接。

The below line maybe the problem. 下一行可能是问题所在。

return $sql->fetch_assoc()['username'];

Function array dereferencing syntax comes with PHP 5.4, your server's php version may be below than 5.4. 函数数组取消引用语法随PHP 5.4一起提供,您服务器的php版本可能低于5.4。

Just check the log in the server and it will be clear. 只要检查服务器中的日志,它就会很清楚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM