首页 > 作文

MySQLi增删改查实例

更新时间:2023-04-08 23:19:03 阅读: 评论:0

mysqli连接 数据库查询单条数据

<?php// 假定数据库用户名:root,密码:root,数据库:tianxiangphp_v1.2 $con=mysqli_connect("local女孩子学什么专业前景比较好host","root","root","tianxiangphp_v1.2");if (mysqli_connect_errno($con)){    echo "连接 MySQL 失败: " . mysqli_connect_error();}// 执行查询$res = $con->query("SELECT * FROM urlist");$data = mysqli_fetch_arr食补不如爱补ay($res);echo "<pre>";var_dump($data);mysqli_clo($con);?>

query()与mysqli_query()使用

放在函数内与函数外mysqli_query($con,”sql语句”);$con->query(”sql语句”);

查询多条数据fetch_all()

<?php// 假定数据库用户名:root,密码:root,数据库:tianxiangphp_v1.2$con=mysqli_connect("localhost","root","root","tianxiangphp_v1.2");if (mysqli_connect_errno($con)){    echo "连接 MySQL 失败: " . mysqli_connect_error();}// 执行查询$res = $con->query("SELECT * FROM urlist");$data = $res->fetch_all(MYSQLI_ASSOC);echo "<pre>";var_dump($data);mysqli_clo($con);?>

插入单条数据mysqli_query()或query()

为true则插入成功
注意:需要插入多条可循环遍历插入

<?php// 假定数据库用户名:root,密码:root,数据库:tianxiangphp_v1.2$con=mysqli_connect("localhost","root","root","tianxiangphp_v1.2");if (mysqli_connect_errno($con)){    echo "连接 MySQL 失败: " . mysqli_connect_error();}// 执行插入$res = mysql辽阳弓长岭王宫温泉i_query($con,"INSERT INTO urlist(mb_type,qy_urid) VALUES (1,666)");if ($res == TRUE) {    echo "ur entry saved successfully.";} el {    echo "INSERT attempt failed" ;}?>

修改数据mysqli_query()或query()

$res = mysqli_query($con,"UPDATE urlist SET `mbid`=77 WHERE urid = 1894");if ($res == TRUE) {    echo "ur entry saved successfully.";} el {    echo "update attempt failed" ;}

删除数据mysqli_query()或query()

mysqli_query($con,”sql语句”);$con->query(”sql语句”);$res = mysqli_query($con,"DELETE FROM urlist WHERE urid = 1895");

统计表总条数

$res = $con->query("SELECT * FROM yzm_ur");//统计总条数$count = mysqli_num_rows($res);

本文地址:https://blog.csdn.net/weixin_39218464/article/details/10898781上海有哪些热力学温度和摄氏温度的关系0

本文发布于:2023-04-08 23:19:01,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/86277fa2669a5dfd57f3c353916e6a48.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:MySQLi增删改查实例.doc

本文 PDF 下载地址:MySQLi增删改查实例.pdf

标签:数据库   语句   数据   假定
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图