Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
mica123

User-Defined Functions And Running Query Questions

Recommended Posts

I have finished the book which is very informative and I have the following questions:

1) You say in Chapter 10 that user-defined functions add extra
memory requirements to the PHP code and that they should not be used
if they call another PHP function or if they have just one line of code.
Even so, I am not sure how one should go about it.
It is difficult to see when they can be used or not.

2) In the last Chapter 13, you have code that refers to running a query. For example:

// Define the query:

$query = "DELETE FROM quotes WHERE quote_id={$_POST['id']} LIMIT 1";

$retrieve = mysql_query($query, $dbc); // Execute the query.

This code executes the query but I am confused. It seems to me
that the code sets the variables - on the face of it is not actually
running anything, yet it does. That's what I don't understand.

Many thanks.
 

Share this post


Link to post
Share on other sites

The answer to your first question is really: you'll learn in time. You'll find that when you do the same process multiple times in an application, it's probably a good candidate for a function. Just avoid creating them when the user-defined function just has a line of code (generally speaking). The example chapter at the end of the has an example of a user-defined function, too. 

 

As for the second question, I'm a bit confused by what you're asking. The first line defines the query and inserts a variable. The second line executes the query (i.e., the second line does the "running"). 

Share this post


Link to post
Share on other sites

Thanks, Larry. Well, I got a little confused here because I was under the impression that

if variables are defined, they don't actually run. However, I can see now that the second variable

is a function which is supposed to be executed once the script is put to work.

Thanks for your patience.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×