Initial configuration

1. Configure the basic information of the database. The attribute $dbConfig is encapsulated in the database encapsulation class. Here, assign a value to it.

Note: Before assigning a value, you should first Introduce database operation class

require 'MysqlPdo.class.php';

//Configure database connection information
$dbConfig=array(
'user'=> ;'root',
'pwd'=>'root',
'dbname'=>'php'
);

2, example Database operation class object

//Instantiate MysqlPdo object
$db=MysqlPdo::getInstance($dbConfig);

3. The error information is stored in a variable array for easy call printing

//Save error information
$error=array();

Error information If you use it frequently, write it in a separate php file and save it for easy calling.

New header.php file, the code is as follows:

<?php if(!empty($error)):?>
    <div>
        <ul>
            <?php foreach ($error as $v): ?>
                <li>
                    <?php echo $v;?>
                </li>
            <?php endforeach;?>
        </ul>
    </div>
<?php endif;?>

New init.php file, the complete code is as follows:

<?php
header("Content-Type:text/html;charset=utf-8");
require 'MysqlPdo.class.php';
//配置数据库连接信息
$dbConfig=array(
    'user'=>'root',
    'pwd'=>'root',
    'dbname'=>'php'
);
//实例化MysqlPdo对象
$db=MysqlPdo::getInstance($dbConfig);
//保存错误信息
$error=array();
Continuing Learning
||
<?php echo "初始化的配置";
submitReset Code