PHP 封装类来访问数据库
2024-10-07 02:21:03
封装访问数据库的类
<?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;
}
}
}
最新文章
- Android面试经验 -- 乐视
- CentOS 6.3 中安装VirtualBOX增强工具失败:Building the main Guest Additions module[FAILED]
- Daily Scrum Meeting ——SixthDay
- 优化数据库的方法及SQL语句优化的原则
- NS2中trace文件分析
- Sql清理日志文件
- 【JavaScript】新浪微博ajax请求后改变地址栏url,但页面不跳转的方案解析
- vim 小技巧总结
- 构建器Constructor的返回值/构建器
- JSP(2)—绝对路径与相对路径、配置Servlet与Servlet注解
- 获取 BaiduMapSDKDemo SHA1 签名
- Scala学习(八)---Scala继承
- genstr.py
- The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
- Python之路,第十七篇:Python入门与基础17
- 第十一周PSP&;进度条
- oracle dblink 查询 tns:无法解析指定的连接标识符
- mysql hang and srv_error_monitor_thread using 100% cpu(已解决)
- 用yield 实现协程 (包子模型)
- linux-redhat-git源码安装
热门文章
- String,到底创建了多少个对象?
- nginx服务学习第二章
- Go语言标准库之fmt.Scan
- A Neural Probabilistic Language Model (2003)论文要点
- Linux系统服务器 GNU Bash 环境变量远程命令执行漏洞修复命令
- Zen Cart 常用SQL命令
- fastjson简单使用demo,@JSONField注解属性字段上与set、get方法上。实体类toString(),实体类转json的区别;_下划线-减号大小写智能匹配
- poj2018 Best Cow Fences[二分答案or凸包优化]
- Session中的方法
- 计算机网络(十一),HTTP和HTTPS区别