Scrigroup - Documente si articole


HomeDocumenteUploadResurseAlte limbi doc
AccessAdobe photoshopAlgoritmiAutocadBaze de dateCC sharp
CalculatoareCorel drawDot netExcelFox proFrontpageHardware
HtmlInternetJavaLinuxMatlabMs dosPascal
PhpPower pointRetele calculatoareSqlTutorialsWebdesignWindows

AspAutocadCDot netExcelFox proHtmlJava
LinuxMathcadPhotoshopPhpSqlVisual studioWindowsXml

Tutorial - Simplifying your scripts by including files


+ Font mai mare | - Font mai mic

Tutorial - Simplifying your scripts by including files

This comes in handy when you have the same information on all your pages, over and over again. For example, connecting to the same

database, printing the same HTML at the top or bottom of a page. It can be used for headers or footers, or for simplifying things.

There are endless possibilities for this. How do we use it?


include ('');


Now, in your '' file, if something like this was put in -


$hello = 'Hello World';

echo $hello;


It would be the same as putting it all in the one file. The only problem is that you have to put the PHP delimiters in the

included file, otherwise it will just display everything that is in there. You can actually name the file to include anything you

want, using .inc just seperates them from the other PHP scripts.

Another thing we can do is -


require ('');


What's the difference? If the required file doesn't exist, then when you run the script it will stop, and give an error. If it's

included instead, it will display a warning and then continue on with the script. In our example, the following errors give an

example of what could happen.

This is for the included file -

Warning: Failed opening '' for inclusion (include_path='') in /tutorial/9.php on line 6

This is for the required file -

Fatal error: Failed opening required '' (include_path='') in /tutorial/9.php on line 6

See the slight difference? For the required file it gives a 'Fatal Error', for the included file it gives a


The only problem with using an 'included' file is if we put passwords in there. Since PostgreSQL doesn't use passwords

when connecting to a database (at least in our example), it's not so important. In our later examples, we'll just make one file

to include with all of our information in it.

There are lots more things that we can do with PHP and PostgreSQL, or just PHP by itself. Try some things out!

Politica de confidentialitate | Termeni si conditii de utilizare



Vizualizari: 879
Importanta: rank

Comenteaza documentul:

Te rugam sa te autentifici sau sa iti faci cont pentru a putea comenta

Creaza cont nou

Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved