我正在尝试在另一个中包含一个php文件(作为第一件事),因为我需要变量,这是MySQL-Statement的结果。这是包含的文件:
的index.php:
<?php
error_reporting(E_ALL); //No errors are shown
require($_SERVER['DOCUMENT_ROOT']."php/db/acp_settings_db_conn.php");
echo $_SERVER['DOCUMENT_ROOT']; //doesn't work
?> /* * some html code, which isn't shown either */
这是包含的文件:
<?php
//Get configuration values (static) from file
require_once($_SERVER['DOCUMENT_ROOT']."acp_settings_db_conf.php");
//Create new object out of connection to db
$db = @new mysqli(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB);
//If there aren't any errors
if(mysqli_connect_errno() == 0){
//Write query, in this case get every row from table
$query = 'SELECT * FROM `meta`';
//If you could prepare query
if($meta_settings = $db->prepare( $query )){
//Execute query
$meta_settings->execute();
//Bind results to custom variables
$meta_settings->bind_result($html_language, $site_author, $site_keywords);
//Fetch result
$meta_settings->fetch();
} else { //If you couldn't prepare query
echo "There is a problem with the query";
}
} else { //If you couldn't connect to DB at all
die("No connection possible: " . mysqli_connect_error());
}
//Close connection
$db->close();
?>
包含的文件工作得很好(用echos检查),现在include正在工作(如果我在包含的文件中有回音,它会弹出index.php)。但是在包含之后,没有显示任何其他内容。所以没有php代码工作,也没有显示任何HTML。 我尝试了一个包含'file.php',但这并不起作用。
所以,自从我度过了这个晚上,如果有人能帮助我,我会很高兴。这是我迈向PHP的第一步,所以要温柔;)
答案 0 :(得分:0)
尝试添加DIRECTORY_SEPARATOR。
require($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "php/db/acp_settings_db_conn.php");