实例
<?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' ];
运行实例 »
点击 "运行实例" 按钮查看在线实例