<?php ///建立数据源 $dbType='mysql'; $host='localhost'; $dbName='data'; $myUser='root'; $myPassword=''; $dsn="{$dbType}:host={$host};dbname={$dbName}"; //建立数据连接 try{ $dbcn= new PDO($dsn,$myUser,$myPassword); }catch(PDOException $e){ die('数据库连接失败'.$e->getMessage()); } ?>