2016-09-22 15:10
浏览 39


I have an insert query which work fine but there is something that I can't understand !

My query :

$query = $db -> prepare ("INSERT INTO table (data_1, data_2, data_3) 
VALUES (:data_1, :data_2, :data_3)");

if ($query -> execute (array (":date_1" => $date_1, ":data_2" => $data_2, ":data_3" => $data_3)) == true AND ($query -> rowCount () > 0))
    echo "Success";
    echo "Failed";

This will return "Success" every time but insert one row into the database every a few minutes ! (Even if I try to refresh the page 1000 time, I will get "Success" but no new row in the database)

I can't find out where is the problem and I didn't find any answer for my problem while searching over internet !

Is there any way else to check if row has been inserted into the database correctly ?

Update :

I just found that when I use different URL like ( and after (, it work great and insert row to the database !

But when I try to use same URL again, the row will not be inserted for about 2 or 3 minutes !

Update 2 :

After working more than 10 hours on the scripts I just thought that maybe it's because of Varnish Cache Server that I use on my server !

Is that possible that Varnish make this problem because of caching pages and so the PHP script doesn't run because it serve by Varnish ?

*I have to check it next week when I am @ home because I don't have access to the server from other networks !

So I just like to know if there is any chance that disabling Varnish resolve this problem ? Because I don't have much experience on Varnish !

Update 3 :

I just disabled Varnish and it work fine, about using Varnish, Is there any way to configure Varnish to work better with dynamic pages ?

*I think but i'm not sure if Varnish work like that with dynamic pages, it can also make some security issue too ! I didn't check anything and i'm not an expert of using Varnish either but with my understanding of PHP I think it's not a good idea to use Varnish for dynamic pages !

图片转代码服务由CSDN问答提供 功能建议

我有一个插入查询工作正常,但有些东西是我无法理解的! \ n


  $ query = $ db  - >  prepare(“INSERT INTO table(data_1,data_2,data_3)
if($ query  - > execute(array(“:date_1”=> $  date_1,“:data_2”=> $ data_2,“:data_3”=> $ data_3))== true AND($ query  - > rowCount()> 0))
 echo“Success”  ; 

每次都会返回“成功”,但会在其中插入一行 数据库每隔几分钟! (即使我尝试刷新页面1000次,我会得到“成功”,但数据库中没有新行)

我无法找到问题所在,我没有 在通过互联网搜索时找不到我的问题的答案!

还有其他方法可以检查行是否已正确插入数据库? < p> 更新:

我刚发现当我使用不同的网址时( )和 在( )之后,它运行良好并将行插入数据库!

但是当我尝试再次使用相同的URL时, 该行不会被插入约2或3分钟!


工作超过10分钟后 脚本上的小时我认为可能是因为我在我的服务器上使用的Varnish Cache Server!

Varnish是否可能因为缓存页面而导致此问题因此PHP脚本 不运行,因为它由Varnish服务?

*我有 o下周我在@ home时检查它,因为我无法从其他网络访问服务器!

所以我只想知道是否有任何机会禁用Varnish解析 这个问题 ? 因为我对清漆没有太多经验!


我刚刚禁用了清漆并且工作正常 很好,关于使用Varnish,有没有办法配置Varnish以更好地使用动态页面?

*我想但我不确定Varnish是否像动态页面那样工作,它 也可以提出一些安全问题! 我没有检查任何东西,我也不是使用Varnish的专家,但我对PHP的理解我认为将Varnish用于动态页面并不是一个好主意!

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douzi7219 2016-09-24 00:14

    If you have Varnish then yes, it will cache the URL. So if you so, the first time it will work because the URL is not cached. The second time Varnish will return the contents of the page and your server will not be called, so the PHP will not "run". You can either turn of Varnish (which I would only recommend if your website does not have many visitors) or use POST and have POST be a pass in your vcl or have something identifiable in your GET for the function you always want to have run (and then do a pass for that something identifiable in your vcl).

    打赏 评论

相关推荐 更多相似问题