当前位置:网站首页>PHP连接mysql原生代码
PHP连接mysql原生代码
2022-07-28 09:26:00 【MountainYanYL】
今天聊一聊原生PHP操作mysql数据库基本操作
1.创建链接
$link = mysqli_connect('localhost','root','');
2. 判断链接是否成功
if(!$link){
exit('mysql数据链接失败');
}
3. 选择要链接的数据库
mysqli_select_db('db_name',$link);
4. 设置字符集
mysqli_set_charset($link,'utf-8');
5. 准备sql语句
$sql = 'xxxxxx';
6.执行查询
$rs = mysqli_query($link,$sql);
7. 处理结果集
【1】
mysqli_fetch_assoc(你发送回来的结果$result)
返回一个一维关联数组
【2】
mysqli_fetch_row($result)
返回一个一维的索引的数组
【3】
mysqli_fetch_array($result);
返回既有关联又有索引的数组
【4】
mysqli_num_rows($result);
返回的是你查询时候结果集的总数
【5】
mysqli_affected_rows($link);
返回你的受影响的行数
【6】
mysqli_insert_id($link);
返回你插入时候的最后的一条自增的id
8. 关闭数据库
mysqli_close($link);
边栏推荐
- FixedWindowRollingPolicy简介说明
- 多线程一定能优化程序性能吗?
- Window source code analysis (II): the adding mechanism of window
- 就这么一个简单的校验,80%的程序员却做不到,更不理解!
- 使用IdentityServer出现过SameSite Cookie这个问题吗?
- Linux操作系统(Centos7)安装MySQL
- How to learn so many conceptual things in database? Seeking method
- How view works
- Express builds a simple local background (1)
- 数据库高级学习笔记--系统包
猜你喜欢

478-82(56、128、718、129)

业务可视化-让你的流程图'Run'起来(4.实际业务场景测试)

数据不会说谎,Plato Farm就是元宇宙龙头

3分钟告诉你如何成为一名黑客|零基础到黑客入门指南,你只需要掌握这五点能力

Salted fish esp32 instance - mqtt lit LED

SQL Server、MySQL主从搭建,EF Core读写分离代码实现

软件测试与质量学习笔记1---黑盒测试

Go language slice vs array panic runtime error index out of range problem solving
C# 窗体应用使用对象绑定 DataGridView 数据绑定

Database core system
随机推荐
Network engineering -- ranking of Chinese universities in Soft Science
Introduction to shardingsphere (I)
软件测试与质量学习笔记2----黑盒测试
Opencv4.60 installation and configuration
路由器固件解密思路
TCP 基础知识
478-82(56、128、718、129)
Plato Farm-以柏拉图为目标的农场元宇宙游戏
业务可视化-让你的流程图'Run'起来(4.实际业务场景测试)
Detailed explanation of various types of files in MySQL
[summary of leetcode weekly competition] the 83rd fortnight competition of leetcode (7.23)
OSS direct upload rails service practice
pycharm使用conda调用远程服务器
Express builds a simple local background (1)
NTU Lin Xuantian's "machine learning cornerstone" problem solving and code implementation | [you deserve it]
matlab基本操作
DAO社区的胜利,Tiger DAO VC胜在治理与共识
分支与循环(1)
数据库高级学习笔记--系统包
ArrayList内部原理解析