riteshn Posted November 30, 2006 Share Posted November 30, 2006 HelloI have one config.php where I have defined some variables.[code]<?php // Database informarion$db_info = array("db_host" => "localhost", "db_user" => "root", "db_pwd" => "", "db_port" => 123, "db" => "preapp");?>[/code]Now in another PHP page:[code]<?phprequire('config.php');print_r($db_info); // 1/* This is a complete PHP page all database related stuff goes here */function ExecuteAndGetResult ( $query ){ print_r($db_info); // 2}?>[/code]In the above case, 1st print_r() works but the 2nd one dosnt. I believe its some GLOBAL variable defining error. What am I doing wrong?Ritesh Link to comment https://forums.phpfreaks.com/topic/28956-variable-defined-in-another-page-not-getting-accessed/ Share on other sites More sharing options...
fert Posted November 30, 2006 Share Posted November 30, 2006 i think to have this work you need to declare $db_info as a global Link to comment https://forums.phpfreaks.com/topic/28956-variable-defined-in-another-page-not-getting-accessed/#findComment-132592 Share on other sites More sharing options...
bljepp69 Posted November 30, 2006 Share Posted November 30, 2006 [code]<?phprequire('config.php');print_r($db_info); // 1/* This is a complete PHP page all database related stuff goes here */function ExecuteAndGetResult ( $query ){ global $db_info; print_r($db_info); // 2}?>[/code] Link to comment https://forums.phpfreaks.com/topic/28956-variable-defined-in-another-page-not-getting-accessed/#findComment-132598 Share on other sites More sharing options...
wildteen88 Posted November 30, 2006 Share Posted November 30, 2006 Or pass it in as the second parameter for the ExecuteAndGetResult function:[code=php:0]require('config.php');print_r($db_info); // 1/* This is a complete PHP page all database related stuff goes here */function ExecuteAndGetResult ( $query, $dbi ){ print_r($dbi); // 2}ExecuteAndGetResult("query_here", $db_info);[/code] Link to comment https://forums.phpfreaks.com/topic/28956-variable-defined-in-another-page-not-getting-accessed/#findComment-132868 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.