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

墨辰丷
Release: 2023-03-28 13:50:02
Original
2536 people have browsed it

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 "失败";
Copy after login

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 '插入失败'; }
Copy after login

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


Related recommendations:

phpArray 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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!