Jump to content



Photo
- - - - -

User-Defined Functions And Running Query Questions


  • Please log in to reply
3 replies to this topic

#1 mica123

mica123

    Newbie

  • Members
  • Pip
  • 13 posts

Posted 18 April 2017 - 12:49 PM

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.
 


  • 0

#2 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4698 posts
  • LocationState College, PA (USA)

Posted 19 April 2017 - 9:34 AM

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"). 


  • 0

#3 mica123

mica123

    Newbie

  • Members
  • Pip
  • 13 posts

Posted 20 April 2017 - 10:11 AM

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.


  • 0

#4 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4698 posts
  • LocationState College, PA (USA)

Posted 24 April 2017 - 9:52 AM

No problem at all! Let me know if you have any other questions!


  • 0