abstract:database.php<?php return [ 'type'=>'mysql', 'host'=>'127.0.0.1', 'dbname'=
database.php
<?php return [ 'type'=>'mysql', 'host'=>'127.0.0.1', 'dbname'=>'php', 'username'=>'root', 'password'=>'root' ];
connect.php
<?php $db=require 'database.php'; $dsn="{$db['type']}:host={$db['host']};dbname={$db['dbname']}"; $username=$db['username']; $password=$db['password']; try{ $pdo=new PDO($dsn,$username,$password); var_dump($pdo); $pdo=null; }catch(PDOException $e){ die("连接失败".$e->getMessage()); }
Correcting teacher:天蓬老师Correction time:2019-08-02 16:28:06
Teacher's summary:完成的不错, PDO连接数据库, 比MySQLi要优雅的多