当前位置:网站首页>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);
边栏推荐
- The secret behind three salary increases a year
- 478-82(56、128、718、129)
- DAO社区的胜利,Tiger DAO VC胜在治理与共识
- LinkedList内部原理解析
- go语言切片Slice和数组Array对比panic runtime error index out of range问题解决
- Analysis of HashSet internal principle
- Some problems about CLR GC tuning
- ECCV 2022 | 无需微调即可推广!基于配准的少样本异常检测框架
- Translation recommendation | debugging bookkeeper protocol - unbounded ledger
- 哪些字符串会被FastJson解析为null呢?
猜你喜欢

刚获融资的Espresso Systems,知识产权与团队道德双双陷入困境

IDC script file running

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

21 day learning challenge - "AUTOSAR from introduction to mastery - practical part"

Use xposed to crack the software

Can multithreading optimize program performance?

NTU Lin Xuantian's "machine learning cornerstone" problem solving and code implementation | [you deserve it]

JDBC connection database

老板:公司系统太多,能不能实现账号互通?

Learn a hammer.Net zero foundation reverse tutorial lesson 3 (shell and homework)
随机推荐
多线程一定能优化程序性能吗?
数据库高级学习笔记--存储函数
NET 3行代码实现文字转语音功能
mq的学习
MATLAB的符号运算
领域事件和集成事件没那么高大上
《我的Vivado实战—单周期CPU指令分析》
Window source code analysis (I): things with decorview
LinkedList内部原理解析
JS array is de duplicated, the ID is the same, and a value is added and merged
路由器固件解密思路
Symbolic operation of MATLAB
Analysis of HashSet internal principle
Detailed explanation of various types of files in MySQL
Pytorch deep learning practice lesson 9 multi classification problems (handwritten numeral MNIST)
数据不会说谎,Plato Farm就是元宇宙龙头
Standing on the shoulders of big men, you can see further
Analysis of the internal principle of ArrayList
Heuristic merging on tree
Scalable search bar, imitating Huawei application market