将连接变量传递给函数 - PDO PHP

问题描述:

When executing functions in the same script:

Should I open a new connection in each function, or should I pass the last connection variable as a parameter?

Is passing the connection variable as a parameter a good practice?

在同一个脚本中执行函数时: p>

我应该打开一个新的 每个函数中的连接,还是应该将最后一个连接变量作为参数传递? p>

将连接变量作为参数传递是一种好习惯吗? p> div>

If you have several functions using the same PDO connection instance, you should pass this variable to your functions instead of instanciating an new object for each function this way you will have less overhead.