Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
11-04-2012, 06:35 AM #1
- Join Date
- Oct 2012
- mother land --india
- Thanked 2 Times in 2 Posts
Information on writing DB include_once for PHP
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 .
11-04-2012, 10:30 AM #2
- Join Date
- Jul 2010
- 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:
.. And then in some public file..PHP Code:
$variable = "This is a variable.";
define( "CONSTANT" , "This is a constant." );
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.PHP Code:
<?php include_once "file.php"; ?>
<title> Your own HTML, obviously. </title>
<p> <?php echo $variable; ?> </p> // Outputs "This is a variable."
<p> <?php echo CONSTANT; ?> </p> // Outputs "This is a constant."