如何編寫 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>

更新於:2020 年 6 月 22 日

301 次瀏覽

開啟你的 職業生涯

完成課程,獲得認證

入門
廣告
© . All rights reserved.