封装访问数据库的类

 <?php

 class DBDA
{
public $host = "localhost"; //数据库地址
public $uid = "root"; //数据库用户名
public $pwd = ""; //数据库密码 //执行SQL语句,返回相应的结果的方法
//参数:$sql代表要执行的SQL语句,$type是SQL语句类型0代表查询1代表其他,$db代表要操作的数据库
public function Query($sql,$type=0,$db="mydb")
{
//1.造连接对象
$dbconnect = new MySQLi($this->host,$this->uid,$this->pwd,$db);
//2.判断连接是否出错
!mysqli_connect_error() or die("连接失败!");
//3.执行SQL语句
$result = $dbconnect->query($sql); if($type==0)
{
return $result->fetch_all();
}
else
{
return $result;
}
}
}

最新文章

  1. Android面试经验 -- 乐视
  2. CentOS 6.3 中安装VirtualBOX增强工具失败:Building the main Guest Additions module[FAILED]
  3. Daily Scrum Meeting ——SixthDay
  4. 优化数据库的方法及SQL语句优化的原则
  5. NS2中trace文件分析
  6. Sql清理日志文件
  7. 【JavaScript】新浪微博ajax请求后改变地址栏url,但页面不跳转的方案解析
  8. vim 小技巧总结
  9. 构建器Constructor的返回值/构建器
  10. JSP(2)—绝对路径与相对路径、配置Servlet与Servlet注解
  11. 获取 BaiduMapSDKDemo SHA1 签名
  12. Scala学习(八)---Scala继承
  13. genstr.py
  14. The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
  15. Python之路,第十七篇:Python入门与基础17
  16. 第十一周PSP&amp;进度条
  17. oracle dblink 查询 tns:无法解析指定的连接标识符
  18. mysql hang and srv_error_monitor_thread using 100% cpu(已解决)
  19. 用yield 实现协程 (包子模型)
  20. linux-redhat-git源码安装

热门文章

  1. String,到底创建了多少个对象?
  2. nginx服务学习第二章
  3. Go语言标准库之fmt.Scan
  4. A Neural Probabilistic Language Model (2003)论文要点
  5. Linux系统服务器 GNU Bash 环境变量远程命令执行漏洞修复命令
  6. Zen Cart 常用SQL命令
  7. fastjson简单使用demo,@JSONField注解属性字段上与set、get方法上。实体类toString(),实体类转json的区别;_下划线-减号大小写智能匹配
  8. poj2018 Best Cow Fences[二分答案or凸包优化]
  9. Session中的方法
  10. 计算机网络(十一),HTTP和HTTPS区别