我有index.php
页面,其中包含settings.php
在settings.php
文件中,我有一些带有数据的PHP变量,如电话号码,姓名等。
在我的index.php
文件中我从MySQL表中选择数据并在屏幕上回显它,我希望能够从数据库中的settings.php
文件中获取变量,这样它们就会回显在index.php
页面上
这怎么可能?
答案 0 :(得分:2)
我希望这就是你要找的东西。
<强>的settings.php 强>
<?php
$valueFromSettings="Settings.php";
<强>的index.php 强>
<?php
include("settings.php");
echo $valueFromSettings; //Prints Settings.php
或者,您可以使用 include_once()
, require()
, require_once()
。所有这些都是语言结构..但要注意 require()
和 require_once()
,因为他们吐了 FATAL
如果要包含的PHP文件不存在,则会出错。
答案 1 :(得分:0)
的settings.php
<?php
$phone='12345';
//declare all of your variables here
?>
并在index.php中将这些变量作为
<?php
include(settings.php);
$query='SELECT phone FROM table where phone="'.$phone.'"';
?>
希望它能帮到你