Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    165
    Thanks
    38
    Thanked 2 Times in 2 Posts

    Information on writing DB include_once for PHP

    Hi All,

    I am just wondering if their is anyway I can write all the db variables at one file and call them in the respective scrip.

    Actually i have seen couple of scripts designed in the same way but I am not understanding how they were called at required place ??

    FYI...attching the script.

    Please help me by sharing any tutorial if you came across in the same way... because I have a DB which as multiple tables related to individual script so, if i want to change the user ID or any other details I need to change it in all the script spite if i can store all this dable name at one place it would be easy for me to manage the administration so, I really want to understand this ....

    appreciated any help .
    Attached Files Attached Files

  • #2
    Regular Coder Custard7A's Avatar
    Join Date
    Jul 2010
    Location
    Australia
    Posts
    286
    Thanks
    32
    Thanked 33 Times in 33 Posts
    Are you familiar with using classes in PHP? It's a great way to group related stuff — like variables — and that is the method the files you attached are using. If you're interested in improving the structure of your scripts that would be a great place to start. You could try the official documentation (http://www.php.net/manual/en/language.oop5.basic.php), or a simple Google search might have some easier to understand tutorials.

    However, there are definitely simpler methods. This should work:

    file.php
    PHP Code:
    <?php

      $variable 
    "This is a variable.";

      
    define"CONSTANT" "This is a constant." );

    ?>
    .. And then in some public file..
    PHP Code:
    <?php include_once "file.php"?>

     <html>
     <head>
     <title> Your own HTML, obviously. </title>
    </head>
     <body>

       <p> <?php echo $variable?> </p> // Outputs "This is a variable."
       <p> <?php echo CONSTANT?> </p> // Outputs "This is a constant."

    </body>
    </html>
    If the value you're intending to use isn't being calculated, altered by the script, or otherwise quite literally variable in nature, then using constants is the best practice.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •