set mysql connect to a php and access them from multiple php functions -
i have php file, connects mysql database using:
$mysqli = mysqli_connect("localhost","user","pass","db"); and on same php, there functions made use of connection, , make querys...
i dont know how set $mysqli entire php , call functions, instead of repeating connection on every function...
(i have 3 functions, need repeat code of connection on every function, making @ end, 3 connections same database. want avoid that, , make 1 connection, , use on 3 functions without making connection more.
is there way?
thanks
there's got dupes, here's 2 ways:
pass function:
$mysqli = mysqli_connect("localhost","user","pass","db"); $something = test($mysqli); function test($conn) { mysqli_query($conn, 'stuff); } or access global variable:
function test() { mysqli_query($globals['mysqli'], 'stuff'); }
Comments
Post a Comment