普通网友 2011-04-19 18:06
浏览 32
已采纳

有没有办法缓存从数据库中填充的多个选择菜单

I have a big form with 132 (12x11) select menus which are populated from the db (MySQL). The problem is obvious: page takes a long time to load because of all those db calls.

The structure of the form: there is a 12 separate sections each for 1 room with 11 dropdowns each (here is the link http://tinypic.com/view.php?pic=6tfjpk&s=7).

From 11 of those dropdowns 8 are the same "Room Description". Is there a way....I could somehow cache those dropdowns especially those 8 from the section 1 (room 1) and then just reload the cache for all other sections (other 11)? I tried to make the array in the function (which creates the dropdown from the database) with dynamic variables assigned to be static static ${$var_name};

but php parser itself doesn't allow dynamic variables to be static.

  • 写回答

2条回答 默认 最新

  • douren5898 2011-04-21 18:34
    关注

    Problem solved!

    @AJ

    1. 1st part of the solution was to save the arrays from query into the session (AJ's recommendations). It helped, but not a lot (not as much as I expected saved me only 0.5 sec of page load. Page was loading before in 4,79 seconds afters this implementation... in 4,47sec's.

    2. This part is an actual solution.

    at the beginning of my code in dorpdown function I had this code:
    $dbh = new PDO(CONFIG_MYSQL_DSN, CONFIG_MYSQL_USERNAME, CONFIG_MYSQL_PASSWORD, array(PDO::ATTR_PERSISTENT => false));

    $dbh -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    which means that I was creating a new db connection every time the function has been called. I made when I created the function some time ago and it was supposed to be used only for testing purposes because I actually have include file on every page which is making sure I'm connected to the database. It has an option array(PDO::ATTR_PERSISTENT => true.

    So, in order to avoid making db connection every time the dropdown function has been called I've set the $dbh to globalglobal $dbh; in that include file. I've also set global $dbh; in the function itself. Now page is loading in ONLY 0.6 seconds instead of 4.76 what is a GREAT IMPROVEMENT!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM