Blogger Information
Blog 27
fans 0
comment 0
visits 22429
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
连接数据库-第五期0417作业
不乖的博客
Original
701 people have browsed it

实例

<?php
    $db = require 'database.php';

    // 配置DSN
    $dsn = "{$db['type']}:host={$db['host']};dbname={$db['dbname']}";

    // 连接测试
    try{
        $pdo = new PDO($dsn , $db['username'], $db['password']);
    }catch (Exception $e){
        echo 'Connecton Failed:'.$e->getMessage();
    }
//    var_dump($pdo);



<?php
   /* $dsn = 'mysql:host=127.0.0.1;dbname=ouyangke';
    $username = 'root';
    $password = 'root';*/

    return [
        'type'=>'mysql',
        'host'=>'127.0.0.1',
        'dbname'=>'ouyangke',
        'username'=>'root',
        'password'=>'root'
    ];

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post