当前位置:网站首页>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);
}
}
边栏推荐
猜你喜欢
随机推荐
令人愉快的 Nuxt3 教程 (一): 应用的创建与配置
Qlik Sense 聚合函数及范围详解(Sum、Count、All、ToTaL、{1})
用iPhone前摄3D人像建模,Meta:我看行
中国生物反应器行业市场投资分析及前景预测报告2022~2028年
Flask,7
`monorepo` 中 `hoist` 机制导致加载配置文件路径的变化
【Arduino】关于“&”和“|” 运算-----多个参数运算结果异常的问题解决
【DC-4靶场渗透】
7.8(6)
jsp通过form表单提交数据到servlet报404
【HQL】(一)json字符串处理json_tuple和get_json_object
NFT租赁提案EIP-5006步入最后审核!让海外大型游戏的链改成为可能
Flask,1-2
运行 npm run xxx 如何触发构建命令以及启动Node服务等功能?
Go (二) 函数部分1 -- 函数定义,传参,返回值,作用域,函数类型,defer语句,匿名函数和闭包,panic
Ansible installation and deployment detailed process, basic operation of configuration inventory
【Yarn】yarn常用命令 查看日志和Kill任务
中国磷化铟晶圆行业发展前景与投资规划分析报告2022~2028年
小码农的第一篇博客
Kettle Spoon 安装配置详解



![7.24[C语言零基础 知识点总结]](/img/b8/3abcee495e70c9ffffc671f2b7d9b1.png)





