简体   繁体   English

PDO-查询执行两次?

[英]PDO - Query executed twice?

My solution 我的解决方案

I was debugging my functions on index.php, i didn't notice that my browser was searching for favicon.icon. 我在index.php上调试函数时,没有注意到浏览器正在搜索favicon.icon。 Currently my router sends the user to index.php if the requested file isn't found, this cause the seccond trigger. 当前,如果找不到请求的文件,我的路由器会将用户发送到index.php,这会导致seccond触发。

You can easly find this @ you're site acces logs! 您可以轻松找到此@您是网站访问日志!

*Sorry for my grammer, i hope its readable.. *对不起我的语法,我希望它可读。

Topic 话题

I have created a little database script, there is only one thing i cannot solve. 我创建了一个小的数据库脚本,只有一件事我无法解决。 When i execute a insert query it wil execute twice. 当我执行插入查询时,它将执行两次。 The values are diffrent(Value = openssl_random_pseudo_bytes). 值是diffrent(值= openssl_random_pseudo_bytes)。

    private function __init($Query = '', $Params = NULL){
    if($this->__getStatus() === false){
        $this->__createConnection();
    }
    $this->__PQuery = $this->__Database->prepare($Query);
        foreach($Params as $param => $value){
            $dataType = PDO::PARAM_STR;
            switch ($value){
                case is_int($value):
                     $dataType = PDO::PARAM_INT;
                break;
                case is_bool($value):
                    $dataType = PDO::PARAM_BOOL;
                break;
                case is_null($value):
                    $dataType = PDO::PARAM_NULL;
                break;
        }
    $this->__PQuery->bindValue($param, $value, $dataType);
    }
    $this->__PQuery->execute();
}

Function call: 函数调用:

$this->__database->Query("INSERT INTO `Serials` (`SerialKey`, `Active`, `ActivatedOn`, `ValidTo`, `Paid`) VALUES (:Serial, 'no', NULL, NULL, 'no');", ['Serial' => openssl_random_pseudo_bytes(10)]);

(Query send it to __init) (查询将其发送到__init)

Can you guys give me any idea's where to look? 你们能给我个主意吗? I'm searching for about 4 hours now. 我现在搜索大约4个小时。

Backtrace before execution 执行前回溯

Core\\Database\\Handler->__init(INSERT INTO Serials ( SerialKey , Active , ActivatedOn , ValidTo , Paid ) VALUES (:Serial, 'no', NULL, NULL, 'no');, Array ([Serial] => n R)) called at [PATH_TO_PUBLIC_HTMLpublic_html/Core/Database/Handler.php:45] Core\\Database\\Handler->Query(INSERT INTO Serials ( SerialKey , Active , ActivatedOn , ValidTo , Paid ) VALUES (:Serial, 'no', NULL, NULL, 'no');, Array ([Serial] => n R)) called at [PATH_TO_PUBLIC_HTMLpublic_html/Core/serialManager/createSerial.php:17] Core\\serialManager\\createSerial->__storeToDB() called at [PATH_TO_PUBLIC_HTMLpublic_html/Core/serialManager/createSerial.php:9] Core\\serialManager\\createSerial->__construct() called at [PATH_TO_PUBLIC_HTMLpublic_html/Controllers/Website.php:6] Website->Home() call_user_func_array(Array ([0] => Website Object (),[1] => Home), Array ()) called at [PATH_TO_PUBLIC_HTMLpublic_html/Core/Routing/Router.php:20] Core\\Routing\\Router->__construct() called at [PATH_TO_PUBLIC_HTMLp 芯\\数据库\\处理程序- > __初始化(INSERT INTO SerialsSerialKeyActiveActivatedOnValidToPaid )VALUES(:串行, '否',NULL,NULL, '否');,阵列([串行] =>在[PATH_TO_PUBLIC_HTMLpublic_html / Core / Database / Handler.php:45]调用Core \\ Database \\ Handler-> Query(INSERT INTO SerialsSerialKeyActiveActivatedOnValidToPaid )VALUES(:Serial ,'no',NULL,NULL,'no');,数组([Serial] => n R))在[PATH_TO_PUBLIC_HTMLpublic_html / Core / serialManager / createSerial.php:17]处调用Core \\ serialManager \\在[PATH_TO_PUBLIC_HTMLpublic_html / Core / serialManager / createSerial.php:9]处调用createSerial-> __ storeToDB()在[PATH_TO_PUBLIC_HTMLpublic_html / Controllers / Website.php:6]处调用Core \\ serialManager \\ createSerial-> __ construct()。在[PATH_TO_PUBLIC_HTMLpublic_html / Core / Routing / Router.php:20]处调用的call_user_func_array(Array([0] =>网站对象(),[1] =>主页),Array())调用了Core \\ Routing \\ Router-> __ construct( )在[PATH_TO_PUBLIC_HTMLp ublic_html/index.php:3] ublic_html / index.php:3]

Backtrace after execution 执行后回溯

Core\\Database\\Handler->__init(INSERT INTO Serials ( SerialKey , Active , ActivatedOn , ValidTo , Paid ) VALUES (:Serial, 'no', NULL, NULL, 'no');, Array ([Serial] => F 7 ,.Kr )) called at [PATH_TO_PUBLIC_HTMLpublic_html/Core/Database/Handler.php:45] Core\\Database\\Handler->Query(INSERT INTO Serials ( SerialKey , Active , ActivatedOn , ValidTo , Paid ) VALUES (:Serial, 'no', NULL, NULL, 'no');, Array ([Serial] => F 7 ,.Kr )) called at [PATH_TO_PUBLIC_HTMLpublic_html/Core/serialManager/createSerial.php:17] Core\\serialManager\\createSerial->__storeToDB() called at [PATH_TO_PUBLIC_HTMLpublic_html/Core/serialManager/createSerial.php:9] Core\\serialManager\\createSerial->__construct() called at [PATH_TO_PUBLIC_HTMLpublic_html/Controllers/Website.php:6] Website->Home() call_user_func_array(Array ([0] => Website Object (),[1] => Home), Array ()) called at [PATH_TO_PUBLIC_HTMLpublic_html/Core/Routing/Router.php:20] Core\\Routing\\Router->__construct() called at [PATH_TO_PUBLIC_HTMLpublic_ Core \\ Database \\ ValidTo > __ init(INSERT INTO SerialsSerialKeyActiveActivatedOnValidToPaid )VALUES(:Serial,'no',NULL,NULL,'no');,数组([Serial] => F (7。,。Kr。))在[PATH_TO_PUBLIC_HTMLpublic_html / Core / Database / Handler.php:45]处调用Core \\ Database \\ Handler-> Query(INSERT INTO SerialsSerialKeyActiveActivatedOnValidToPaid )VALUES(:在[PATH_TO_PUBLIC_HTMLpublic_html / Core / serialManager / createSerial.php:17]处调用的Serial,'no',NULL,NULL,'no');,数组([Serial] =>F 7。,。Kr ))在[PATH_TO_PUBLIC_HTMLpublic_html / Core / serialManager / createSerial.php:9]处调用serialManager \\ createSerial-> __ storeToDB()在[PATH_TO_PUBLIC_HTMLpublic_html / Controllers / Website.php:6]处调用Core \\ serialManager \\ createSerial-> __ construct()。 ()call_user_func_array(Array([0] => Website Object(),[1] => Home),Array())在[PATH_TO_PUBLIC_HTMLpublic_html / Core / Routing / Router.php:20]处调用在[PATH_TO_PUBLIC_HTMLpublic_中调用了__construct() html/index.php:3] html / index.php:3]

[NOTE] My hosting company are under attack.. [注意]我的托管公司受到攻击。

*Sorry for my grammer, did my best.. *对不起我的语法师,我已经尽力了。

Cause of the problem 问题原因

My browser was looking for favicon.ico, but it didnt exist. 我的浏览器正在寻找favicon.ico,但它不存在。 If a file/page didnt exist the request is routed to index.php 如果文件/页面不存在,则请求将路由到index.php

Mistake 错误

  • Debugging on index.php 在index.php上调试
  • Missing favicon.ico 缺少favicon.ico

What did i learned? 我学到了什么?

  • Never debug on the homepage, see below why. 切勿在首页上进行调试,原因如下。
  • If there are 2 requests are incomming(when 1 made) Probably the browser sends the second request to look for the favicon.ico (In my case if the page doenst exist return to home) 如果有两个请求传入(发出1个请求),可能是浏览器发送了第二个请求以查找favicon.ico(在我的情况下,如果页面确实存在,请返回首页)

Solution

1 Don't debug on you're index.php 1不要在index.php上调试

2 Add the following code to you're html 2将以下代码添加到您的html中

<link rel="shortcut icon" href="#" />

Sorry For My Broken English 对不起,我的英语不好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM