calling individual functions on a remote php page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tolkienarda
    Contributor
    • Dec 2006
    • 316

    calling individual functions on a remote php page

    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
  • cassbiz
    New Member
    • Oct 2006
    • 202

    #2
    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

    Code:
    function dbconnect()
    {
            global $db, $t_global;
            $db_con = @MYSQL_CONNECT($db['server'],$db['user'],$db['passwortd]) or die ($t_global['query_false']);
            $db_check = @MYSQL_SELECT_DB($db['name']);
    }
    
    blah, blah, blah
    The in the actual php page that you are using you will need to include the function page

    Code:
    <?
                    include "function.php";
    ?>
    And to call the function in your php page you will need to do like the following

    Code:
    $connect = dbconnect();
    Hope the above helps and Good Luck!

    Comment

    • tolkienarda
      Contributor
      • Dec 2006
      • 316

      #3
      cool awesome thanks

      eric

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        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:

        Comment

        • cassbiz
          New Member
          • Oct 2006
          • 202

          #5
          Originally posted by ronverdonk
          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?

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            When you assign like
            Code:
            $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:

            Comment

            • cassbiz
              New Member
              • Oct 2006
              • 202

              #7
              OK, I see what you are saying.

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

              Code:
              dbconnect ();
              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.

              Comment

              • ronverdonk
                Recognized Expert Specialist
                • Jul 2006
                • 4259

                #8
                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:

                Comment

                • cassbiz
                  New Member
                  • Oct 2006
                  • 202

                  #9
                  kewlness!

                  Thanks for that snippet, I will integrate it into my own scripts.

                  Comment

                  • tolkienarda
                    Contributor
                    • Dec 2006
                    • 316

                    #10
                    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

                    Comment

                    • ronverdonk
                      Recognized Expert Specialist
                      • Jul 2006
                      • 4259

                      #11
                      That is the best compliment you could give the team. Thanks.

                      Ronald :cool:

                      Comment

                      Working...