php更新数据库并返回所影响的行数

时间:2016-07-10
本文章向大家介绍一个php实例源码(更新数据库中的数据并返回所影响的行数),主要使用到mysql_affected_rows函数,需要的朋友可以参考一下。

php更新数据库并返回所影响的行数

<html>
  <body>
  <?php
  $host="mysql153.secureserver.net";
  $uname="java2s";
  $pass="password";
  $database="java2s";
  $tablename="Employee";
  
  $connection= mysql_connect($host,$uname,$pass)  or die("Database connection failed!<br>");
  $result=mysql_select_db($database) or die("Database could not be selected");
  $query = "UPDATE Employee SET Firstname=\"new Name\" where id=2";
  $result = mysql_query($query);

  if (!$result) {
     die(" Query could not be executed.<br>");
  } else {
  echo "<table> ";
  echo " <tr>";
  echo "   <td colspan=\"2\">";
  echo "     <center><b>".mysql_affected_rows()." record updated successfully</b></center>";
  echo "   </td>";
  echo "  </tr>";
  echo "  <tr>";
  echo "    <td>";
  echo "      <div align=\"right\"> Name</div>";
  echo "   </td>";
  echo "   <td>".$name. "</td>";
  echo " </tr>";
  echo " <tr>";
  echo "   <td>";
  echo "     <div align=\"right\">E-mail</div>";

  echo "    </td>";
  echo "    <td>".$email. "</td>";
  echo "  </tr>";
  echo "  <tr>";
  echo "    <td>";
  echo "      <div align=\"right\"> CustomerID</div>";
  echo "    </td>";
  echo "    <td>".$customerid. "</td>";
  echo "  </tr>";
  echo "</table>";
  }
  ?>
  </body>
  </html>

上一页 下一页

原文地址:http://www.manongjc.com/article/1166.html