By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,716 Members | 1,431 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,716 IT Pros & Developers. It's quick & easy.

calling individual functions on a remote php page

tolkienarda
100+
P: 316
hi all

i am building a small private school management program and i use alot of the same loops, update statements, and whatnot and i would like to put them all into one php file divided into their own functions. i was just wondering if it is possible to call an individual function on a remote php page.

thanks
eric
Jan 19 '07 #1
Share this Question
Share on Google+
10 Replies


cassbiz
100+
P: 202
Of course you can,

Create all of the functions on a separate page ie function.php

then of course you list your functions on that page

Expand|Select|Wrap|Line Numbers
  1. function dbconnect()
  2. {
  3.         global $db, $t_global;
  4.         $db_con = @MYSQL_CONNECT($db['server'],$db['user'],$db['passwortd]) or die ($t_global['query_false']);
  5.         $db_check = @MYSQL_SELECT_DB($db['name']);
  6. }
  7.  
  8. blah, blah, blah
  9.  
  10.  
The in the actual php page that you are using you will need to include the function page

Expand|Select|Wrap|Line Numbers
  1. <?
  2.                 include "function.php";
  3. ?>
  4.  
And to call the function in your php page you will need to do like the following

Expand|Select|Wrap|Line Numbers
  1. $connect = dbconnect();
  2.  
Hope the above helps and Good Luck!
Jan 19 '07 #2

tolkienarda
100+
P: 316
cool awesome thanks

eric
Jan 19 '07 #3

ronverdonk
Expert 2.5K+
P: 4,258
Small correction: in order to use this command[php]$connect = dbconnect();[/php] the dbconnect function must return a value, otherwise you cannot assign it to the $connect variable.

Ronald :cool:
Jan 19 '07 #4

cassbiz
100+
P: 202
Small correction: in order to use this command[php]$connect = dbconnect();[/php] the dbconnect function must return a value, otherwise you cannot assign it to the $connect variable.

Ronald :cool:

Hi Ronald,

I don't quite understand what you mean when you say a variable. Now I know enough to not know -- LOL

What type of variable has to be assigned?
Jan 19 '07 #5

ronverdonk
Expert 2.5K+
P: 4,258
When you assign like
Expand|Select|Wrap|Line Numbers
  1. $connect = dbconnect(); 
you actually assign the result of the function dbconnect() to the variable $connect.
Since the function dbconnect() does not return anything, no data or boolean, the assignment has no meaning. You cannot properly use variable $connect. Maybe you don't want to, but then the assignment is useless.

Ronald :cool:
Jan 19 '07 #6

cassbiz
100+
P: 202
OK, I see what you are saying.

The way I have used it has been many times as a straight function call

Expand|Select|Wrap|Line Numbers
  1. dbconnect ();
  2.  
but I have also used it as in the previous example with other functions.

thanks again.

I still have a lot to learn and just don't quite completely understand the manuals and tutorials.
Jan 19 '07 #7

ronverdonk
Expert 2.5K+
P: 4,258
Yes, a straight function call is fine. But, in this case, I would have passed on a false if an error had occurred during the connect or db select, and a true when no error had occurred.

So the statement then could be [php]if (!dbconnect())
die ("Some error at connect");
else
// continue processing[/php]
Ronald :cool:
Jan 19 '07 #8

cassbiz
100+
P: 202
kewlness!

Thanks for that snippet, I will integrate it into my own scripts.
Jan 20 '07 #9

tolkienarda
100+
P: 316
maybe not the best place to put this post but...

I love this site. thescripts is the reason i have a job. i was hired to build php scripts with mysql database communication three months ago and i knew html and had heard of php but had never seen the code. now thanks to ron and other members I am building database driven sites without you guys and your detailed descriptions and fast replys to questions i probably wouldn't have a job

thanks
eric
Jan 21 '07 #10

ronverdonk
Expert 2.5K+
P: 4,258
That is the best compliment you could give the team. Thanks.

Ronald :cool:
Jan 21 '07 #11

Post your reply

Sign in to post your reply or Sign up for a free account.