PHP: SQL connection in File 1, SQL functions in File 2 not working -
i have file 1 called init.php
holds sql details , sql connection:
<?php $sql = array( 'user' => 'user', 'password' => 'pass', 'server' => '192.168.100.1', 'db' => 'xe' ); $conn = oci_connect($sql['user'], $sql['password'], $sql['server'].'/'.$sql['db']); if (!$conn) { $e = oci_error(); trigger_error( htmlentities($e['message'], ent_quotes), e_user_error ); } include("functions.php"); ?>
i have file 2 called functions.php
holds sql functions:
<?php function is_accessible($a, $b) { $stid = oci_parse($conn, "select c1 t1 o1 = $a"); oci_execute($stid); $row = oci_fetch_array($stid, oci_num); if ($row['0'] == $b) { return true; } else { return false; } } function ... ?>
the functions.php
file not seem want use connection have in init.php
, why this?
if put sql connection directly in is_accessible
function works.
you should use global define connection inside function
function is_accessible($a, $b) { global $conn; $stid = oci_parse($conn, "select c1 t1 o1 = $a"); oci_execute($stid); $row = oci_fetch_array($stid, oci_num); if ($row['0'] == $b) { return true; } else { return false; } }
and dont forget run function
Comments
Post a Comment