PHP PDO inserts a piece of data, and the solution to the situation where two pieces of data appear repeatedly

不言
Release: 2023-03-24 18:40:01
Original
2909 people have browsed it

The content of this article is the solution to the situation where PHP PDO inserts a piece of data and two data appear repeatedly. It has a certain reference value. Now I share it with everyone. Friends in need can refer to it

$dsn    =   sprintf("mysql:host=%s;dbname=%s;charset=utf8", $host, $dbName);$_dbHandle    =   new PDO($dsn, $user, $password, $option);
$sql = "insert into `name` (`age`) values (18)";
Copy after login


$_dbHandle-><span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold;">exec</span>($sql);

非常简单的sql插入,但是每次执行的时候会出现两条一模一样的数据,
在我的环境下就出现问题,在别人的环境里就没有问题,于是我怀疑是环境问题。
页面刷新的时候根本看不出重复刷新的样子,但实际上真的执行了两条,只是看不出来。
因为我当时在编写rewrite规则,nginx没有给我报任何问题,但是我只操作了这里,所以认定是rewrite的问题。
具体原因如下:
由于nginx的重写问题(rewrite)的时候,在location的模块中,错误的语法,导致了项目被重复执行了两次,因为是nginx的重写跳转问题,
在nginx层面就进行跳转了,还不等响应数据,就已经跳转了,所以我们在断点调试的时候无法检验出这个问题。
如果遇到同样的场景,可以根据实际情况尝试把rewrite文件删除,或者修改来测试是否为nginx的问题。注:apache没有测过,但是也有可能也会有类似的情况。
Copy after login

           

The above is the detailed content of PHP PDO inserts a piece of data, and the solution to the situation where two pieces of data appear repeatedly. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template