我正在尝试将一个php文件包含在另一个文件中(作为第一件事),因为我需要变量,这些变量是MySQL语句的结果。以下是包含以下内容的文件:
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 */这是get包含的文件:
<?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();
?>包含的文件工作得很好(用回显检查),现在包含也可以工作了(如果我在包含的文件中有回显的东西,它会在index.php上弹出)。但在包含之后,将不会显示任何其他内容。所以没有php-code在工作,也没有显示任何html。我尝试了一个包含'file.php',但它不起作用。
既然我把晚上都花在这上面了,如果有人能帮我,我会很高兴。这些是我在PHP中的第一步,所以要轻柔一些;)
发布于 2013-03-17 08:09:21
尝试添加DIRECTORY_SEPARATOR。
require($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "php/db/acp_settings_db_conn.php");https://stackoverflow.com/questions/15456173
复制相似问题