php - include() not picking up previously defined variables -
i'm pretty sure need ol` fashion brain check. have never seen such silly issue , i'm sure missed dumb.
index.php
<? require('lib/conf.php'); /* bunch of code here */ echo get_user('username',$_session['uid']);
lib/conf.php
<? /* bunch of secret stuff here */ $dbcon = new pdo("mysql:host=$db_host;dbname=$db_name", $db_user, $db_pass); //////////// // // includes / requirements // //////////// include('functions/user.functions.php');
functions/user.functions.php
<? function get_user($dvar,$uid){ $psql = $dbcon->prepare("select :dvar ls_users uid=:uid"); $dbcon->begintransaction(); $psql->execute(array(":dvar"=>$dvar,":uid"=>$uid)); foreach($psql $row){ return $row[$dvar]; } }
however attempting such simple thing, continue get:
undefined variable: dbcon in <b>/home/lodestar/public_html/lib/functions/user.functions.php</b> on line <b>10</b> call member function prepare() on non-object in <b>/home/lodestar/public_html/lib/functions/user.functions.php</b> on line <b>9
so, feel though i'm going crazy please check brain , tell me i'm missing?
notes
line number in error not reflect correct line number in example code
call global variable declare global variable in function use
function get_user($dvar,$uid){ global $dbcon; ..... }
Comments
Post a Comment