dongtao6842 2016-09-22 15:10
浏览 42


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 !

  • 写回答

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).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥60 SOL语句中Where查询中的 from to 语句能不能从小到大换成从大到小(标签-SQL)
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 请教一下c语言的代码里有一个地方不懂
  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))