当前位置:网站首页>php连接数据库脚本
php连接数据库脚本
2022-08-03 05:22:00 【wuqinghalasao】
<?php
class DB{
private $host;
private $username;
private $password;
private $database;
private $port;
private $conn;
//构造方法
function __construct($host='127.0.0.1',$username='root',$password='',$database='test',$port=3306)
{
$this->host=$host;
$this->username=$username;
$this->password=$password;
$this->database=$database;
$this->port=$port;
// echo "建立连接<br/>";
// 调用连接函数
$this->connection();
}
// 连接函数
private function connection(){
// 给连接变量赋值,并建立连接
$this->conn=mysqli_connect($this->host,$this->username,$this->password,$this->database,$this->port) ;
mysqli_query($this->conn,"set names utf8");
}
// 查询函数
function query($sql){
$result=mysqli_query($this->conn,$sql);
$rows=mysqli_fetch_all($result);
// foreach ($rows as $r){
// echo "<br/>";
// foreach($r as $v){
// echo "$v ";
// }
// }
return $rows;
}
function Update($sql){
$result=mysqli_query($this->conn,$sql);
// print($result);
// if($result == 1){
// print("更新成功");
// }
// else{
// print("更新失败");
// }
}
function __destruct()
{
mysqli_close($this->conn);
}
}
边栏推荐
- BeanFactory和FactoryBean的区别
- Ansible installation and deployment detailed process, basic operation of configuration inventory
- uni-app 滚动到顶部/指定位置
- pta a.1003 的收获
- Django从入门到放弃三 -- cookie,session,cbv加装饰器,ajax,django中间件,redis缓存等
- MySQL 索引详解和什么时候创建索引什么时候不适用索引
- Navicat 解决隔一段时间不操作出现延时卡顿问题
- Apache2-XXE漏洞渗透
- Let small program development into ` tailwind jit ` era
- arm64麒麟安装paddlehub(国产化)注意事项
猜你喜欢
随机推荐
Flask,1-2
vivado遇到的问题
用C语言来实现五子棋小游戏
Kettle Spoon 安装配置详解
【HQL】(一)json字符串处理json_tuple和get_json_object
中国水产养殖行业市场投资分析及未来风险预测报告2022~2028年
令人愉快的 Nuxt3 教程 (一): 应用的创建与配置
MySQL 安装报错的解决方法
编写一个函数 reverse_string(char * string)(两种方法实现)7.26
Qlik Sense 聚合函数及范围详解(Sum、Count、All、ToTaL、{1})
MySQL EXPLAIN 性能分析工具详解
spark sql 报错 Can‘t zip RDDs with unequal numbers of partitions
【源码解读】火爆的二舅币真的跑路了吗?
MySQL 索引检索原理和B+Tree数据结构详解
The result of request.getParameter is on
玩转Markdown(2) —— 抽象语法树的提取与操纵
中国聚氯乙烯(PVC)土工膜发展动态及投资前景预测报告2022~2028年
MySQL 唯一索引 UNIQUE KEY 会导致死锁?
用C语言来实现扫雷小游戏
【DC-4 Range Penetration】









