我有一个index.php
页面,其中包括settings.php
在settings.php
文件中,我有一些带有数据的 PHP 变量,例如电话号码、姓名等。
在我的index.php
文件中,我从 MySQL 表中选择数据并在屏幕上回显它,我希望能够将settings.php
文件中的变量保存在数据库中,以便它们在index.php
页面上回显
这怎么可能?
我希望这就是你要找的。
设置.php
<?php
$valueFromSettings="Settings.php";
索引.php
<?php
include("settings.php");
echo $valueFromSettings; //Prints Settings.php
或者,您可以使用include_once()
, require()
, require_once()
.. 所有这些都是语言结构.. 但请注意,如果要包含的 PHP 文件不存在require()
,require_once()
它们会吐出错误。FATAL
设置.php
<?php
$phone='12345';
//declare all of your variables here
?>
并在 index.php 中获取这些变量为
<?php
include(settings.php);
$query='SELECT phone FROM table where phone="'.$phone.'"';
?>
希望对你有帮助