PHP中mysqli_affected_rows作用行数返回值分析

更新时间:2023-06-21 20:04:47 阅读: 评论:0

PHP中mysqli_affected_rows作⽤⾏数返回值分析
小长颈鹿本⽂实例分析了PHP中mysqli_affected_rows作⽤⾏数返回值。分享给⼤家供⼤家参考。具体分析如下:
mysqli中关于update操作影响的⾏数可以有两种返回形式:
1. 返回匹配的⾏数
2. 返回影响的⾏数
默认情况下mysqli_affected_rows返回的值为影响的⾏数,如果我们需要返回匹配的⾏数,可以使⽤mysqli_real_connect函数进⾏数据库连接的初始化,并在函数的flag参数位加上:
美容神器MYSQLI_CLIENT_FOUND_ROWS return number of matched rows, not the number of affected rows
普通格式:
复制代码代码如下:
int mysqli_affected_rows ( mysqli link )
oop格式:
复制代码代码如下:
class mysqli {
int affected_rows
}
看下例⼦:
普通模式,代码如下:
复制代码代码如下:
<?php
$link = mysqli_connect("localhost", "my_ur", "my_password", "world");
if (!$link) {
printf("Can't connect to localhost. Error: %sn", mysqli_connect_error());
exit();
音响英语
}
/* Inrt rows */
mysqli_query($link, "CREATE TABLE Language SELECT * from CountryLanguage");
printf("Affected rows (INSERT): %dn", mysqli_affected_rows($link));
mysqli_query($link, "ALTER TABLE Language ADD Status int default 0″);
/* update rows */
mysqli_query($link, "UPDATE Language SET Status=1 WHERE Percentage > 50″);
printf("Affected rows (UPDATE): %dn", mysqli_affected_rows($link));
/* delete rows */
基因概念
mysqli_query($link, "DELETE FROM Language WHERE Percentage < 50″);
printf("Affected rows (DELETE): %dn", mysqli_affected_rows($link));
/* lect all rows */
$result = mysqli_query($link, "SELECT CountryCode FROM Language");
printf("Affected rows (SELECT): %dn", mysqli_affected_rows($link));
mysqli_free_result($result);
/* Delete table Language */关于武松的故事
mysqli_query($link, "DROP TABLE Language");
/* clo connection */
mysqli_clo($link);
>
oop模式,代码如下:
复制代码代码如下:
<?php
$mysqli = new mysqli("localhost", "my_ur", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %sn", mysqli_connect_error());
exit();
}
/* Inrt rows */
$mysqli->query("CREATE TABLE Language SELECT * from CountryLanguage"); printf("Affected rows (INSERT): %dn", $mysqli->affected_rows);
$mysqli->query("ALTER TABLE Language ADD Status int default 0″);
ppp是什么/* update rows */
$mysqli->query("UPDATE Language SET Status=1 WHERE Percentage > 50″); printf("Affected rows (UPDATE): %dn", $mysqli->affected_rows);
/* delete rows */
$mysqli->query("DELETE FROM Language WHERE Percentage < 50″);
printf("Affected rows (DELETE): %dn", $mysqli->affected_rows);
/* lect all rows */
$result = $mysqli->query("SELECT CountryCode FROM Language");
printf("Affected rows (SELECT): %dn", $mysqli->affected_rows);
平板支撑的作用$result->clo();
/* Delete table Language */
单人独马
$mysqli->query("DROP TABLE Language");
/* clo connection */
$mysqli->clo();
>
希望本⽂所述对⼤家的php程序设计有所帮助。

本文发布于:2023-06-21 20:04:47,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1048809.html

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

标签:返回   代码   函数
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图