Passing database connection by reference in PHP

后端 未结 7 2214
清歌不尽
清歌不尽 2020-12-31 09:05

The question is if a database connection should be passed in by reference or by value?

For me I\'m specifically questioning a PHP to MySQL connection, but I think it

7条回答
  •  清歌不尽
    2020-12-31 09:43

    A database connection does not actually hold the underlying values, so you don't have to worry about losing assignments made inside a function. Metaphorically, you can think of a DB connection as, say, a runway number -- "OK, DB Connection 12 is cleared to be used for a query" -- The query and result set use the connection, and may need exclusive access for awhile, but the connection does not know anything about the underlying data.

提交回复
热议问题