码迷,mamicode.com
首页 > 其他好文 > 详细

PDO

时间:2016-05-16 08:11:57      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:

包含PDO用法的类

<?php
class DB
{
	public $host = "localhost";
	public $uid = "root";
	public $pwd = "";
	
	public function Query($sql,$type=0,$db="mydb")
	{
		$d = new MySQLi($this->host,$this->uid,$this->pwd,$db);
		!mysqli_connect_error() or die("连接失败!");
		$result = $d->query($sql);
		if($result)
		{
			if($type==0)
			{
				return $result->fetch_all();
			}
			else
			{
				echo "执行成功!";
				return $result;
			}
		}
		else
		{
			echo "执行失败!";
		}
	}
	public function Querypdo($sql,$typepdo=0,$db="mydb",$fwq="mysql")
	{
		$dsn = "$fwq:dbname=$db;host=$this->host";  
		$pdo = new PDO($dsn,$this->uid,$this->pwd);
		$stm = $pdo->prepare($sql);
		if($stm->execute())
		{
			if($typepdo == 0)
			{
				return $stm->fetchAll(PDO::FETCH_NUM);
			}
			else
			{
				echo "执行成功!";
				return $stm->execute();
			}
		}
		else
		{
			echo "执行失败!";
		}
	}
}

  

PDO

标签:

原文地址:http://www.cnblogs.com/1116zsc/p/5496861.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!