当前位置:网站首页>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);
边栏推荐
猜你喜欢

2022-7-27周报

Leetcode - hashtable topic
![[log] what does a log do? What is a log factory? Configuration and use of log4j? log4j. Properties file configuration, log4j jar package coordinates](/img/ae/096b558bc1342447205b442a244aae.png)
[log] what does a log do? What is a log factory? Configuration and use of log4j? log4j. Properties file configuration, log4j jar package coordinates

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

SD卡介绍(基于SPEC3.0)

Machine learning (10) -- hypothesis testing and regression analysis

Can multithreading optimize program performance?

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

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

关于CLR GC调优的一些问题
随机推荐
PlatoFarm进展不断,接连上线正式版以及推出超级原始人NFT
Introduction to SD card (based on spec3.0)
Buckle 376 swing sequence greedy
分支与循环(1)
老板:公司系统太多,能不能实现账号互通?
ECCV 2022 | can be promoted without fine adjustment! Registration based anomaly detection framework for small samples
Heuristic merging on tree
JS提升:实现flat平铺的底层原理
ARouter源码解析(一)
Analysis of the internal principle of ArrayList
Opencv installation configuration test
数据库高级技术学习笔记1--Oracle部署和PL/SQL综述
Seeing clearly is more important than walking fast, because you can go far only when you walk right
业务可视化-让你的流程图'Run'起来(4.实际业务场景测试)
Retrofit源码解析
就这么一个简单的校验,80%的程序员却做不到,更不理解!
This wechat plug-in is very easy to use
21 day learning challenge - "AUTOSAR from introduction to mastery - practical part"
学个锤子 | .Net零基础逆向教程 第三课(壳与作业)
fastjson中@jsonType注解的功能简介说明