以下代码无法连接:
$file_open = fopen("logindetails.txt","r");
if($file_open){
$user = fgets($file_open);
$pass = fgets($file_open);
$server = fgets($file_open);
}
echo "user: ",$user,"password: ",$pass,"server: ",$server;
@$db_handle = mysql_connect($server,$user,$pass);
但输出:
user: root password: usbw server: localhost
logindetails.txt包含:
root
usbw
localhost
此代码连接时:
$user = "root";
$pass = "usbw";
$server = "localhost";
echo "user: ",$user,"password: ",$pass,"server: ",$server;
@$db_handle = mysql_connect($server,$user,$pass);
我无法解决这个问题。我无法猜到原因。
答案 0 :(得分:1)
您使用fgets
读取的变量也包含换行符。
$user == "root\n";
$pass == "passw\n";
这就是为什么MySQL不会认为它们有效。
所以,你应该:
trim()
他们config.php
而不是文本文件。