How to use global variables in PHP

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.