我刚刚发现了mysql和mysqli,所以我真的是一个初学者。我有一个函数,我正在使用(来自包含的 php 文件)与所有变量一起连接到服务器,OO 样式。它就像主页的魅力,但我有一个页面(使用来自表单的 get 请求)尝试使用该函数并失败。这是函数:
function connect(){
$servername = "";
$dbusername = "";
$dbpassword = "";
$dbname = "";
$mysqli = new mysqli($servername, $dbusername, $dbpassword, $dbname);
if($mysqli->connect_errno){
echo "Failed to connect to MySQL: (".$mysqli->connect_errno.") ".$mysqli->connect_error;
}
return $mysqli;
}
GET请求有什么东西阻止了它吗?这种做法是不恰当的吗?我一直在整理文档,但我非常困惑。以下是我用来调用函数的代码:
include_once '/tools/config.php';#This is the file the function is in
#(I even copied the text from the working file)
$mysql = connect();
我的调试相当于注释掉各个行,直到它起作用。有没有更好的方法?谢谢。
这个函数的语法没有任何问题。问题出在我的包含语句中。谢谢大家的帮助。