/ Published in: PHP
usage is simple: $result = mysqliquery($query,dbconn('local')); for instance. if written in patterns, this should probably be a singleton, but I haven't bothered converting it - feel free to comment with your modification though!
Expand |
Embed | Plain Text
$local = false; $master = false; function db_conn($type) { // echo 'in db_conn'; if(${$type} && ${$type}->ping()) { // echo 'connection already exists and is alive'; return ${$type}; } else { // echo 'connection does not exist, attempting to connect'; ${$type} = new mysqli($host[$type],'user','password','database'); if(${$type}) { return ${$type}; } else { err('Could not connect to '.${$type}.' database.'.mysqli_connect_error()); return false; } } }
You need to login to post a comment.
