PHP-将数据库信息写入PHP文件? [英] PHP - Writing Database Information To A PHP File?

查看:73
本文介绍了PHP-将数据库信息写入PHP文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,很抱歉,如果没有显示不是堆栈溢出的内容的代码..但是我不知道在哪里进行此操作.我有一个基本的CMS,我正在尝试分发它.我要这样做,以便例如在进入/cms/install时,他们设置数据库信息,并将不同的信息集成到CMS中.现在我的问题是,允许用户存储该数据库信息的最佳方法是什么? Cookie似乎不是正确的方法.我可以将数据库信息存储在数据库中吗?不太确定该怎么做.或多或少.临时存储用户在完整CMS到来之前提供的数据库信息的最佳方法是什么.

First off, I'm sorry if this shows no code which is not what Stack Overflow is about..But I have no clue where to go on this. I have a basic CMS I made, and I am trying to distribute it. I want to make it so that upon going to /cms/install for example, they set the database info, and different info to integrate into the CMS. Now my issue is, what would be the best method to allow the user to store that database info? A cookie seems to not be the right way..Could I store database info inside of a database? Not too sure where to go on this. More or less. What is the best way to temporarily store the database information the user gave before arrival of the full CMS.

<?php 
$fopen = fopen('config.php', 'w'); 
fwrite($fopen, '1'); 
write($fopen, '<?php $dbname = '$_POST['database']'; $dbpassword = '$_POST['password']';     ?>'); fclose($fopen); 
?> 

这项工作吗?

推荐答案

创建一个脚本,该脚本使用数据库连接变量生成配置文件(例如config.php). 完成新的配置文件后,不要忘记设置正确的文件权限.

Create a script that generates a config file (e.g. config.php) with the database connection variables. Don't forget to set the right file-permissions after you done with a new config file.

更新:

$config .= "<?php\n"; 
$config .= "\$database = '".$_POST['database ']."';\n";
$config .= "\$user= '".$_POST['user']."';\n";
$config .= "\$pass= '".$_POST['pass']."';\n"; 
$config .= "?>\n"; 

file_put_contents("config.php", $config);

这篇关于PHP-将数据库信息写入PHP文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆