2013-03-17 59 views
0

我试图在另一个包括一个php文件(作为第一件事),因为我需要变量,这是MySQL声明的结果。下面是该文件的蒙山包括:php-include后没有显示任何内容

的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(); 
?> 

所包含的文件工作得很好(有回声检查的话) ,现在include还在工作(如果我在包含的文件中回显了一些内容,它会在index.php中弹出)。但在包含之后,没有其他显示。所以没有php代码正在工作,也没有显示任何html。 我试过了一个包含'file.php',但这并不起作用。

所以,因为我在这个晚上度过了一个晚上,所以如果有人能帮助我,我会很高兴。这些是我在PHP中的第一步,所以要温柔;)

+0

您是否尝试删除包含文件中的<?php'? – fedorqui 2013-03-17 00:04:34

+4

'error_reporting(E_ALL)'是不够的。确保你也ini_set('display_errors',true)'。 – Tchoupi 2013-03-17 00:05:32

+0

嗨,@ fedorqui:这没有用,浏览器只显示了代码。 @Mathieu Imbert:不知道我会需要ini_set。有两个很好的错误,它们现在已经修复并且正在工作。谢谢:) – 2013-03-17 00:12:17

回答

0

尝试添加DIRECTORY_SEPARATOR。

require($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "php/db/acp_settings_db_conn.php");