简体   繁体   English

应用程序中的数据库连接管理

[英]database connection manngement in application

I am developing a application that is in php and PostgreSQL . 我正在开发php和PostgreSQL中的应用程序。

What I want to know is which of these is best? 我想知道的是哪个最好?

  1. I should create connection every time i have to make a query like using pg_connect and close it after the query operations 每当我必须使用pg_connect进行查询时,都应该创建连接,并在查询操作后将其关闭
  2. Or should i start the connection first time at the initial launch 或者我应该在首次启动时第一次启动连接

Please guide me the correct way to achieve my objective. 请指导我实现目标的正确方法。

Connect at the start of your script, close it at ending. 在脚本的开头连接,在结束时将其关闭。 No need to re-connect on each query. 无需在每个查询上重新连接。

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

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