MINI SUPPORTERS:

 

 

 

 

 
Using Includes with PHP
         by Jubba

Introduction
This tutorial is just a down and dirty explanation on how to use the include() function in an attempt to make your PHP code-writing life a little easier. Basically the include() function includes the file placed inside the parenthesis as the argument inside of your main file. I use this a lot when I am connecting to a database over multiple files. I keep all of my connection variables in my include file and call them throughout my main scripts. Kind of like this:

Include file: include.php
<?
// This is my include file
$dbHost = "localhost";
$dbUser = "root";
$dbPass = "";
$dbName = "MyDataBase";
?>

This is the file that I name include.php Its the one that I will be placing inside of my main scripting files. Then all you need to do to place your information inside of your file is one small line of code:

Main file:
<?
include("include.inc");
// The rest of my code would go here...
// and here...
// and here...
// and here...
// and here...
?>

Now there is another function similar to this, require() the only difference between them is that require() returns a fatal error and stops the script from executing. Include() doesn't do that; the script continues to run even if the file that you are including contains some type of an error. I know that this tutorial didn't cover 100% of the bases. It was just a simple explanation. If you would like more info you can check out PHP.net or feel free to ask on the forums in the Server-side Scripting Forum.

Jubba

 

SUPPORTERS:

cloud storage
cloud storage
kirupa.com's fast and reliable hosting provided by Media Temple. Creative web apps. Make your own free flash banners and photo slideshows.
HTML5 CSS3 Mobile Gallery for iPhone, iPad Flash effects. Art without coding.
Flipping Book - page flip flash component. Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery
X-Platform Application Development for Flash Free Flash Components Download - XML Templates, Players and Galleries.

two computer monitors

US Direct

Learn how to advertise on kirupa.com  
 
SHARE:



MINI SUPPORTERS: