php - Share mysqli connection -


i switched ext/mysql mysqli in php project. in project, extensively used connection reuse feature of mysql_connect setting new_link parameter set false.

as far understand, there no such mechanism in mysqli_connect; return new connection though same host , user used. correct? there other function can mimic reuse-behaviour?

nb: see prepending host p: create persistent connection. however, cannot used in case, part of project relies on temporary tables.

update:
actual mysqli object embedded in db handler class manages access database. handler used interact db.

i oversimplified problem because wanted focus on question if mysqli can automatically reuse single connection multiple calls mysqli_connect identical parameters. project extenstion framework , provides multiple entry points , hooks. cannot control order or number of function calles hosting framework extension. each part of extension creates instance of db handler, reuse actual underlying connection.

the creation of db handler done though db-factory. probabely have implement sort of connection-caching there myself...

nope, mysqli ext doesn't follow lazy mysql ext behavior, , reason.
so, have explicitly address mysqli object. problem, though, variable scope. long have $mysqli object visible, can use right.

however, there problem: shouldn't address $mysqli object in application code @ all. problem old mysql ext , problem mysqli ext - it not intended used in application code is.

one have create sort of wrapper, encapsulate database related stuff, , in application code use wrapper class only.

so, such wrapper, create instance of it, , pass every class , function parameter.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -