将多个PHP变量赋给MySQL值


Assign multiple PHP variables to MySQL values

我正在为一个网站做一个简单的CMS,它是这样做的:

(config . php)

<?php
$title= "My website title";
$something= "Some text here";
// There are around 300 other vars like that.
// All text from the website comes from this file.
?>

(example.php)

<php require ('config.php'); ?>
<html>
    <head>
        <title><?php echo $title ?></title>
    </head>
    <body>
        <p><?php echo $something ?></p>
    </body>
</html>

但是现在我想把它传递给MySQL。我一开始没有这样做,因为我对编码真的很陌生,但在把所有东西放在一起的过程中,我觉得已经准备好使用数据库和管理面板了。

假设我已经建立了一个MySQLi连接,如何使config.php变量从数据库中提取数据,而不是静态字符串?

我如何做到这一点,而不会使系统过载,每个页面加载数百个查询?

如果您希望在同一文件的不同页面中使用不同的变量。然后,通过

获取当前页面名称
$page_name = substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);

根据页面名称从数据库中取出您的信息。

config。

<?php
  if($page_title == 'example.php'){
    $title= $db_title;               // This variable will come from database...
    $something= $db_something;
  }
  else if($page_title == 'example_2.php'){
    $title= $db_title_2;
    $something= $db_something_2;
  }
  etc...
?>