donglong7338 2013-06-22 15:48
浏览 16
已采纳

使用mysqli_change_user,还是不使用?

I am setting up a database class in my php application, and I was planning on using either PDO or MySQLi. I was thinking of persistant connections, but I am wondering if this is the best idea. I saw, unlike PDO, MySQLi automaticly resets the state of the connection with mysqli_change_user().

However, as noted in the PHP manual, it states that the mysqli_change_user() function is expensive and could degrade performance, but that you can also disable it.

I currently have two questions:

  • Are persistant connections a good idea? And if so, with PDO or MySQLi?
  • Is the mysqli_change_user() function so expensive that it nullifies the performance increase of using a persistant connection? If so, is it such a bad idea to disable it, if you have written proper code?
  • 写回答

2条回答 默认 最新

  • dongyikong6207 2013-06-22 16:14
    关注

    Are persistant connections a good idea?

    Yes, in general. Save for the cheap shared hostings where you shouldn't use it.

    And if so, with PDO or MySQLi?

    If you want to change user - mysqli is the only choice. If not - it's irrelevant.

    Is the mysqli_change_user() function so expensive that it nullifies the performance increase of using a persistant connection?

    My common sense is telling me that it is not.

    If so, is it such a bad idea to disable it, if you have written proper code?

    Personally, I wouldn't bother at all.

    There is a one problem with performance issues. Some of them are real ones but some just imaginary, taken out of nowhere. A strange thing - these latter makes huge impression to developers. It always makes me wonder, how much time and efforts being spend to solve a problem which noone ever noticed or measured on a live application.

    What I would suggest is to profile your existing application (if any), and I bet 100:1 that you will find several places in your code which do 1000 times stronger impact on performance than this imaginary expense.

    So, I would keep it.

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

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)