我们如何编写PHP脚本来通过MySQL查询计算受影响的行?
PHP使用mysql_affected_rows()函数来找出查询改变了多少行。为了说明这一点,我们有以下示例-
示例
<html>
<head>
<title>Rows affected by query</title>
</head>
<body>
<?php
$dbhost = 'localhost:3036';
$dbuser = 'root';
$dbpass = 'rootpassword';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully<br />';
mysql_select_db( 'TUTORIALS' );
$result_id = mysql_query ($query, $conn_id);
# report 0 rows if the query failed
$count = ($result_id ? mysql_affected_rows ($conn_id) : 0);
print ("$count rows were affected\n");
?>
</body>
</html>热门推荐
7 孙媳妇祝福语简短
10 新婚抖音祝福语简短
11 收围巾的祝福语简短
12 婚礼祝福语简短情话文案
13 新年祝福语简短的个性
14 写给兄弟的祝福语简短
15 迎新祝福语简短20字
16 中秋祝福语简短版大全
17 给孙子祝福语简短独特
18 薛之谦祝福语简短