如果我尝试在浏览器中打开这个简单的文件:
<?php
require_once 'classes/settings.php';
class Mysql {
private $conn;
function __construct() {
$this->conn = new mysqli (DB_SERVER,DB_USER,DB_PASSWORD,DB_MEMBER) or die('There was a problem connecting to the database.');
if ($this->conn->connect_errno) {
echo "Failed to connect to MySQL: (" . $this->conn->connect_errno . ") " . $this->conn->connect_error;
}
//echo $mysqli->host_info . "\n";
}
function verify_Username_and_Pass($un, $pwd) {
$query = "SELECT *
FROM users
WHERE username = ? AND password = ?
LIMIT 1";
if($stmt = $this->conn->prepare($query)) {
$stmt->bind_param('ss',$un,$pwd);
$stmt->execute();
if($stmt->fetch()) {
$stmt->close();
return true;
}
}
}
}
?>
我收到此警告错误:
Warning: require_once(classes/settings.php): failed to open stream: No such file or
directory in /var/www/classes/Mysql.php on line 3 Fatal error: require_once(): Failed
opening required 'classes/settings.php' (include_path='.:/usr/share/php:/usr/share/pear')
in /var/www/classes/Mysql.php on line 3
我不明白为什么,文件setting.php
在那个文件夹里,那么问题出在哪里?
编辑:
如果我对另一个文件执行相同的操作,例如:
<?php
require_once 'classes/settings.php';
$host = "localhost";
$user = "root";
$pass = "pass";
$databaseName = "membership";
$tableName = "users";
//--------------------------------------------------------------------------
// 1) Connect to mysql database
//--------------------------------------------------------------------------
$con = mysql_connect($host,$user,$pass);
$dbs = mysql_select_db($databaseName, $con);
//--------------------------------------------------------------------------
// 2) Query database for data
//--------------------------------------------------------------------------
$result = mysql_query("SELECT * FROM $tableName"); //query
$array = mysql_fetch_row($result); //fetch result
//--------------------------------------------------------------------------
// 3) echo result as json
//--------------------------------------------------------------------------
echo json_encode($array);
?>
这样,它可以正常工作,我不明白为什么文件和路径是正确的,因为在第二段代码中所有工作。