本文实例分析了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
}
看下例子:
普通模式,代码如下:
复制代码 代码如下:<"localhost", "my_user", "my_password", "world");
if (!$link) {
printf("Can't connect to localhost. Error: %sn", mysqli_connect_error());
exit();
}
/* Insert 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));
/* select 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");
/* close connection */
mysqli_close($link);
"codetitle">复制代码 代码如下:<"localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %sn", mysqli_connect_error());
exit();
}
/* Insert 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″);
/* 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);
/* select all rows */
$result = $mysqli->query("SELECT CountryCode FROM Language");
printf("Affected rows (SELECT): %dn", $mysqli->affected_rows);
$result->close();
/* Delete table Language */
$mysqli->query("DROP TABLE Language");
/* close connection */
$mysqli->close();
?>
希望本文所述对大家的php程序设计有所帮助。
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
更新日志
- 王艺翔.2024-至暖(EP)【乐人】【FLAC分轨】
- 樊桐舟《流年微词HQCD》WAV+CUE
- Rachmaninoff-SymphonicDances-BerlinerPhilharmoniker,KirillPetrenko(2024)[24-96]
- 岡部啓一《NieRGestaltReplicantOrchestralArrangementAlbum》24-96\FLAC
- 群星《心光》[FLAC/分轨][307.76MB]
- 许茹芸《讨好》[WAV+CUE][1G]
- 唐磊《丁香花》[WAV+CUE]
- 刘德华.2001-天开了【BMG】【WAV+CUE】
- 群星.2013-顾嘉辉大师经典演唱会3CD【爱我音乐】【WAV+CUE】
- 费翔.2000-费常翔念2CD【环球】【WAV+CUE】
- Rachmaninoff-SuitesNos.12,TheSleepingBeauty-MikuOmine,TakakoTakahashi(2024)[24-
- 童丽《影视金曲(1:1黄金母盘版)》[WAV]
- 柏菲·胭花四乐《胭花四乐》限量开盘母带ORMCD[低速原抓WAV+CUE]
- 群星《监听耳机天碟》2018[WAV分轨][1G]
- 群星《娱协奖原创金曲合辑》滚石[WAV+CUE][1.1G]