自定义php函数的mysql数据库pdo包装

define('DB_DSN','mysql:dbname=数据库名;charset=UTF8');
define('DB_USER','root');
define('DB_PASSWORD','');
function dbInsert($sql,$data=null){
$pdo = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
$stat = $pdo->prepare($sql);
return $stat->execute($data);
}
function dbSelect($sql,$data=null){
$pdo = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
$stat = $pdo->prepare($sql);
$stat->execute($data);
return $stat->fetch(PDO::FETCH_NAMED);
}
function dbSelectAll($sql,$data=null){
$pdo = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
$stat = $pdo->prepare($sql);
$stat->execute($data);
return $stat->fetchAll(PDO::FETCH_NAMED);
}
function dbUpdate($sql,$data=null){
$pdo = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
$stat = $pdo->prepare($sql);
return $stat->execute($data);
}
function dbDelete($sql,$data=null){
$pdo = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
$stat = $pdo->prepare($sql);
return $stat->execute($data);
}

posted @ 2015-04-27 21:27  纳兰那些事儿  阅读(173)  评论(0编辑  收藏  举报