如何设置php项目通过用户界面安装数据库

时间:2021-03-25 23:56:49

I have enough experience to build websites in PHP using CakePhp framework but now i'm trying to build website like others professional where GUI is given to user to configure/install website by providing host, database name, user name, password where website have 1 file called "install.php" it takes database detail to connect and create database.

我有足够的经验用CakePhp框架在PHP中构建网站,但是现在我正在尝试建立像其他人一样的网站,通过提供主机,数据库名,用户名,密码,在网站上有一个名为“install”的文件来配置/安装网站。它使用数据库细节来连接和创建数据库。

Here my question comes ,when website prompt user to enter detail for database and after getting values for host, database name, user, password; we run databse.sql file to create database but after that how our project knows the user name,password, database name, host to connect beacause normally we write database credentials in file of php to configure so in this way how we handle connection between our PHP website and database.

在这里,我的问题是,当网站提示用户输入数据库的详细信息,以及获取主机、数据库名、用户、密码的值后;我们运行数据库。创建数据库的sql文件,之后我们的项目如何知道用户名、密码、数据库名、主机连接信标,因为通常我们在php文件中编写数据库凭证来配置,这样我们就可以处理php网站和数据库之间的连接。

one solution i'm thinking to write some keyword in database configuration file and replace them with user provided detail.

我正在考虑的一个解决方案是在数据库配置文件中编写一些关键字,并用用户提供的详细信息替换它们。

If you have better solution then please guide me.

如果你有更好的解决办法,请指导我。

1 个解决方案

#1


2  

i found answer for this

我找到了答案

config.php:

config . php:

return array(
    'host' => 'localhost',
    'username' => 'not-defined',
);

setting.php:

setting.php:

$config = include 'config.php';
$config['username']= 'root';
file_put_contents('config.php', '<?php return ' . var_export($config, true) . ';');

Updated config.php now contains the following:

更新后的配置。php现在包含以下内容:

return array(
     'host' => 'localhost',
     'username' => 'root',
);

you can add add/update other attributes in same way.

您可以以相同的方式添加添加/更新其他属性。

#1


2  

i found answer for this

我找到了答案

config.php:

config . php:

return array(
    'host' => 'localhost',
    'username' => 'not-defined',
);

setting.php:

setting.php:

$config = include 'config.php';
$config['username']= 'root';
file_put_contents('config.php', '<?php return ' . var_export($config, true) . ';');

Updated config.php now contains the following:

更新后的配置。php现在包含以下内容:

return array(
     'host' => 'localhost',
     'username' => 'root',
);

you can add add/update other attributes in same way.

您可以以相同的方式添加添加/更新其他属性。