I am using in my PHP file a function which is defines inside the PHP file. He structure of the code is like below
//--- db connection
$dbconn = pg_connect(...
// function definition
function myfunction(){
$f_stmt = '.....'
$f_result = pg_query_params($dbconn,$f_stmt, ....
$val = pg_fetch_result($f_result, 'COL_VAL');
return $val;
}
//---- general logic
$stmt = '....'
$result = pg_query_params($dbconn,$stmt, ....
while ($row = pg_fetch_assoc($result)) {
echo myfunction()
}
When I am trying to use the same connection in the function $dbconn like tje sample above I am receiving a connection error. When I create a new connection $dbconn2 inside the function for its own usage it works. If this is the solution isn't it bad for the performance? or is there a proper way?
$dbconnaccessible inside the functionglobal $dbconn;at the top of the function (before other code) will do the trick