如何编写 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
");
?>
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP