我试图在另一个文件中包含一个 php 文件(作为第一件事),因为我需要变量,它们是 MySQL 语句的结果。这是包含的文件:
索引.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();
?>
包含的文件工作得很好(用回声检查),现在包含也工作了(如果我在包含的文件中有回显的东西,它会在 index.php 上弹出)。但是在包含之后,什么都没有显示。所以没有 php 代码在工作,也没有显示任何 html。我尝试了一个包含'file.php',但这也不起作用。
因此,由于我在此度过了一个晚上,如果有人可以帮助我,我会很高兴。这些是我在 PHP 中的第一步,所以要温柔;)