Scrigroup - Documente si articole

Username / Parola inexistente      

Home Documente Upload Resurse Alte limbi doc  


AccessAdobe photoshopAlgoritmiAutocadBaze de dateCC sharp
CalculatoareCorel drawDot netExcelFox proFrontpageHardware
HtmlInternetJavaLinuxMatlabMs dosPascal
PhpPower pointRetele calculatoareSqlTutorialsWebdesignWindows
WordXml

AspAutocadCDot netExcelFox proHtmlJava
LinuxMathcadPhotoshopPhpSqlVisual studioWindowsXml

Tutorial - Simplifying your scripts by including files

php

+ Font mai mare | - Font mai mic



DOCUMENTE SIMILARE

Trimite pe Messenger
Tutorial - Simplifying your scripts by including files
Introduction to PHP


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?

<?php

include ('example.inc');

?>

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

<?php

$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 -

<?php

require ('example.inc');



?>

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 'hello.inc' for inclusion (include_path='') in /tutorial/9.php on line 6

This is for the required file -

Fatal error: Failed opening required 'hello.inc' (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

'Warning'.

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



DISTRIBUIE DOCUMENTUL

Comentarii


Vizualizari: 570
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 2021 . All rights reserved

Distribuie URL

Adauga cod HTML in site