Forum Moderators: coopster

Message Too Old, No Replies

A couple of questions regarding include files and database connection

         

sapphyre

7:04 am on Mar 25, 2004 (gmt 0)



Hi... I just have a couple of quick questions...

First, what is the difference between using this:


<?php include("page.html");?>

and this:

<?php require("page.html");

In addition, does using include files take up more bandwidth or anything?

Second question... when connecting to the database, one assigns the database connection info (password, host, etc) to a variable like this:


$connect = @mysql_connect($host, $user, $password);

When making mysql queries, I've noticed that one can either do this:


mysql_query($sqlStatement,$connect);

or simply this:

mysql_query($sqlStatement);

What are the advantages/disadvantages of including the $connect after the sql statement?

One more quick question... what is the difference between using echo and using print?

I just started learning php recently, so I'm still not clear about a few basic things... thanks for your time, everyone :)

=^..^=

Timotheos

4:42 pm on Mar 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld!

This is from the most excellent manual at php.net [php.net]

Include vs. Require

The two constructs are identical in every way except how they handle failure. include() produces a Warning while require() results in a Fatal Error. In other words, use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless.

Query

mysql_query() sends a query to the currently active database on the server that's associated with the specified link identifier. If link_identifier isn't specified, the last opened link is assumed.

No other advantage that I know except saving keystrokes but if you have more then one connection it would be good to specify.

Echo vs Print
For a short discussion about the differences between print() and echo(), see this FAQTs Knowledge Base Article [faqts.com]

jamie

5:04 pm on Mar 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hi sapphyre,

something to be aware of is that php code and bandwidth don't have much to do with each other.

all php code is processed on the server. only the ouputted html is sent to the browser. this means you can have a 2000 line script which produces a 10 line html page - the lucky surfer only has to download the 10 line html page. he will however have to wait whilst the server processes the 2000 line script.

you shouldn't have to worry about that though, php parsing speed is very quick. i believe the smarty template system has at least 2000 lines of code which have to be processed before each html page is generated and sent to the browser - and smarty is used in a LOT of websites.

good luck with the coding and don't forget to use the php manual as timotheos says - you can even download a windows helpfile version which means you can install it all (plus user notes) on your pc at home (look out for the dreamweaver help file extension if you are lucky enough to use DW).

otherwise visit devshed.com and zend.com for LOADS of excellet and clearly explained tutorials

good luck with the coding :-)