Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
February 09, 2012, 01:31:31 PM

Pages: [1]   Go Down
  Print  
Author Topic: set up and call global $var  (Read 619 times)
durangod
Galactic Royalty
*****
Offline Offline

Posts: 203


« on: March 12, 2010, 01:00:07 PM »

hi i have been working all day on getting this var to pass to another function but it will not..

in my website config i have

Code:
$link=mysql_connect($xxxNST_DB_HOST,$xxxNST_DB_USER,$xxxNST_DB_PASS);
                $db=mysql_select_db($xxxNST_DB_NAME,$link);

i want to use the $link var and $db in another file in another function

so i have tried to set  
Code:
global_session('$link');
and the other one in my config then ref it by
Code:
$GLOBALS['$link']
in the file i want to use it in but it wont ass

i have also tried
$link=mysql_connect($GLOBAL['$xxxNST_DB_HOST']): blah blah and so on  format but still wont

so how do i grab this var in this function and use it please..
« Last Edit: March 12, 2010, 02:12:55 PM by durangod » Logged
durangod
Galactic Royalty
*****
Offline Offline

Posts: 203


« Reply #1 on: March 12, 2010, 01:01:44 PM »

hold on lol i just saw the sticky on this,  sorry i didnt notice that before, guess i need to read more lol sorry about that, if i still need help ill post again thanks
Logged
durangod
Galactic Royalty
*****
Offline Offline

Posts: 203


« Reply #2 on: March 12, 2010, 01:30:27 PM »

ok so i read the global var sticky but im still sort of lost, since that var is set in my config file im guessing that i can just use REQUEST to grab $link at the top of my php file that i want to use it in....

i can  just put the string in my php file just as it is in the config but the problem is im getting a error when i do that.  this is why i was thinking i needed to make it global

Code:
Access denied for user: 'xxxxx@localhost' (Using password: NO
  the xxxxx is my site root dir name

rest of the site works fine no login issues with the site or lp at all, just this call is all
« Last Edit: March 12, 2010, 01:36:01 PM by durangod » Logged
clever_clown
Galactic Royalty
*****
Offline Offline

Posts: 252



« Reply #3 on: March 21, 2010, 06:00:04 AM »

where did you defined this:
Code:
$link=mysql_connect($xxxNST_DB_HOST,$xxxNST_DB_USER,$xxxNST_DB_PASS);
                $db=mysql_select_db($xxxNST_DB_NAME,$link);

is it inside the function? or it's at the top if the page header?
Logged
MrPhil
Berserker Poster
*****
Offline Offline

Posts: 5083



« Reply #4 on: March 21, 2010, 08:50:20 AM »

Neither global_session('$link'); nor $GLOBALS['$link'] is going to work, because your variable is inside single quotes. I'm not sure if $link is already a string value, in which case you could simply drop the quotes, or it needs to be in double quotes ". In ", the value for the variable will be substituted; in ' it probably is just staying as the literal string "$link". Anyway, the first thing to try is changing ' to ".

When you say you're trying "to pass it to another function", is that on another page or just in another file that's being included or required on this page? In the latter case, simply global $link; might do the job.
Logged

durangod
Galactic Royalty
*****
Offline Offline

Posts: 203


« Reply #5 on: March 22, 2010, 11:51:24 AM »

what i did was i just copied the function from another php file and copied it to this php file and that seems to work, i really dont like to have to do that because replication should not be necessary but it seems to be working, i will try phil to test that out and see if i can remove the new function and just call the value when i get a chance, thanks so much for your help...
Logged
clever_clown
Galactic Royalty
*****
Offline Offline

Posts: 252



« Reply #6 on: March 22, 2010, 01:23:28 PM »

1. can you provide you code so we can help you better

2. don't forget to define the session $link in the global inside the function in order to use the param in or out...

Cheers,
Logged
Pages: [1]   Go Up
  Print  
 
Jump to: