Home >Backend Development >PHP Tutorial >How to use PHP to monitor whether data is successfully inserted into the Mysql database
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 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!