PHP how to use global variables PHP global variables
The result is no output. how can I define and use global variables?
Reply to discussion (solution)$ Vfp_oledb_CString = "Provider = VFPOLEDB.1; Data Source = d:/testoledb; Collating Sequence = MACHINE ";
Testgol ();
Function testgol (){
Global $ vfp_oledb_CString;
Echo $ vfp_oledb_CString;
}
We do not recommend that you use the global keyword. Instead, use $ GLOBALS to overwrite the global variable.
Install yac. Shared memory between processes, very easy to use.
Do I need to declare it again during the call? .
This string is used to declare the directory location of the. vfp table. I want to use it as a configuration file to include
And then use it in various functions of a PHP file to achieve this effect. it is better to use that method.
You can also use $ GLOBAL to overwrite GLOBAL variables.
$ Vfp_oledb_CString = "Provider = VFPOLEDB.1; Data Source = d:/testoledb; Collating Sequence = MACHINE ";
Testgol ();
Function testgol (){
Echo $ GLOBALS ['vfp _ oledb_CString '];
}
If your string is fixed, you can define it as a constant. the constant range is global. You can access constants anywhere in the script without worrying about the zone.
Solved the problem by using constants. thank you for your patience.