Home  >  Article  >  Backend Development  >  How to use PHP to monitor whether data is successfully inserted into the Mysql database

How to use PHP to monitor whether data is successfully inserted into the Mysql database

墨辰丷
墨辰丷Original
2018-05-30 15:20:512622browse

How to use code in PHP to determine whether data is successfully inserted into the Mysql database? This article gives two solution methods. You can choose the corresponding method according to your needs. Friends in need can follow the editor to learn together.

Preface

This article mainly introduces whether the monitoring data in the PHP code is successfully inserted into the Mysql database. These two methods can be used. Not much to say below, let’s take a look at the detailed solutions.

Solution

The first is to judge through the mysql_query() function:

if(mysql_query('insert into ......'))//插入成功后返回true,失败返回false
 echo "成功";
else 
 echo "失败";

The second method is to judge whether the return value of the mysql_affected_rows() function is greater than 0:

mysql_query($sql1);$flag1 = mysql_affected_rows();
mysql_query($sql2);$flag2 = mysql_affected_rows();
mysql_query($sql3);$flag3 = mysql_affected_rows();
if($flag1>0 && $flag2>0 && $flag3>0 ){
 echo '插入成功';

}else{
 echo '插入失败';
}

The above is the entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations:

php Array implementation merges the same key values ​​​​according to a certain key value to generate a new two-dimensional Detailed explanation of the array method

PHP uses imagick extension to implement the method of merging images

PHP implements the calculation of the number of days between dates Methods

The above is the detailed content of How to use PHP to monitor whether data is successfully inserted into the Mysql database. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn