Dumbfounded

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sheldon Glickler

    Dumbfounded

    I have a script, testsql.php that I run and it works well.

    Here are the guts:

    session_start() ;
    require_once("s qlLoginDB.php") ;
    mssql_select_db ($database_apbL ogin, $apbLogin);
    $_SESSION['curSpeaker'] = '1000129';
    query = "SELECT * FROM speakers WHERE iOldSpeakerId=' " .
    $_SESSION['curSpeaker'] . "'";
    $result = mssql_query($qu ery, $apbLogin);// or die(mssql_error ());
    echo "Result: " . $result;

    It gives me a resource ID number.

    When I call a function from another function from the a main page, and this
    script is cut and pasted in, the result comes up empty.

    I am at a total loss here.

    Shelly



  • Justin Koivisto

    #2
    Re: Dumbfounded

    Sheldon Glickler wrote:[color=blue]
    > I have a script, testsql.php that I run and it works well.
    >
    > Here are the guts:
    >
    > session_start() ;
    > require_once("s qlLoginDB.php") ;[/color]

    If this is going into a function or included file, it should be an
    absolute path. For instance, if the sqlLoginDB.php file is lcoated in
    the same directory where this code is found, you should use:

    require_once dirname(__FILE_ _).'/sqlLoginDB.php' ;

    That way, no matter what the current working directory is, the file can
    be found.
    [color=blue]
    > mssql_select_db ($database_apbL ogin, $apbLogin);[/color]

    No mssql_connect? IF you paste this into a function, you will need to be
    sure that you are referencing your db connection either through $GLOBAL
    or explicitly define it as global in the function. You should also check
    to see that the call succeeded by checking it's return value.
    [color=blue]
    > $_SESSION['curSpeaker'] = '1000129';
    > query = "SELECT * FROM speakers WHERE iOldSpeakerId=' " .
    > $_SESSION['curSpeaker'] . "'";
    > $result = mssql_query($qu ery, $apbLogin);// or die(mssql_error ());
    > echo "Result: " . $result;[/color]

    You may want to try something like:

    if(!is_resource ($result)){
    // there was a query error of some sort
    return mssql_error();
    }else{
    // the query was a success
    }

    --
    Justin Koivisto, ZCE - justin@koivi.co m

    Comment

    • ZeldorBlat

      #3
      Re: Dumbfounded


      Justin Koivisto wrote:[color=blue]
      > Sheldon Glickler wrote:[color=green]
      > > I have a script, testsql.php that I run and it works well.
      > >
      > > Here are the guts:
      > >
      > > session_start() ;
      > > require_once("s qlLoginDB.php") ;[/color]
      >
      > If this is going into a function or included file, it should be an
      > absolute path. For instance, if the sqlLoginDB.php file is lcoated in
      > the same directory where this code is found, you should use:
      >
      > require_once dirname(__FILE_ _).'/sqlLoginDB.php' ;
      >
      > That way, no matter what the current working directory is, the file can
      > be found.[/color]

      Absolutely not. This would imply that sqlLoginDB.php lives in the same
      (internet-accessible) directory as the calling file. Files that you
      include (database connection code, class definitions, etc.) should live
      in a directory /outside/ the webserver document tree. Set the include
      path directive in php.ini appropriately.
      [color=blue]
      >[color=green]
      > > mssql_select_db ($database_apbL ogin, $apbLogin);[/color]
      >
      > No mssql_connect? IF you paste this into a function, you will need to be
      > sure that you are referencing your db connection either through $GLOBAL
      > or explicitly define it as global in the function. You should also check
      > to see that the call succeeded by checking it's return value.[/color]

      So I'm guessing that you call mssql_connect() inside sqlLoginDB.php.
      What exactly are you pasting into your function? All of the code you
      pasted above (including the session stuff) ? Be careful that you
      aren't calling session_start() more than once or you might have some
      weird problems.
      [color=blue]
      >[color=green]
      > > $_SESSION['curSpeaker'] = '1000129';
      > > query = "SELECT * FROM speakers WHERE iOldSpeakerId=' " .
      > > $_SESSION['curSpeaker'] . "'";
      > > $result = mssql_query($qu ery, $apbLogin);// or die(mssql_error ());
      > > echo "Result: " . $result;[/color]
      >
      > You may want to try something like:
      >
      > if(!is_resource ($result)){
      > // there was a query error of some sort
      > return mssql_error();
      > }else{
      > // the query was a success
      > }
      >
      > --
      > Justin Koivisto, ZCE - justin@koivi.co m
      > http://koivi.com[/color]

      Post what you have inside sqlLoginDB.php as well as the entire function
      you have created so we have a better idea of what might be going on.

      Comment

      • Norman Peelman

        #4
        Re: Dumbfounded

        "Sheldon Glickler" <sheldonlg@bell south.net> wrote in message
        news:sA5Lf.2064 $u%.579@bignews 1.bellsouth.net ...[color=blue]
        > I have a script, testsql.php that I run and it works well.
        >
        > Here are the guts:
        >
        > session_start() ;
        > require_once("s qlLoginDB.php") ;
        > mssql_select_db ($database_apbL ogin, $apbLogin);
        > $_SESSION['curSpeaker'] = '1000129';
        > query = "SELECT * FROM speakers WHERE iOldSpeakerId=' " .
        > $_SESSION['curSpeaker'] . "'";
        > $result = mssql_query($qu ery, $apbLogin);// or die(mssql_error ());
        > echo "Result: " . $result;
        >
        > It gives me a resource ID number.
        >
        > When I call a function from another function from the a main page, and[/color]
        this[color=blue]
        > script is cut and pasted in, the result comes up empty.
        >
        > I am at a total loss here.
        >
        > Shelly
        >
        >[/color]

        It's giving you a resource id because that's all your asking it for... you
        also need something like:

        if ($result)
        {
        while ($my_resource_d ata = mssql_fetch_arr ay($result,MSSQ L_ASSOC))
        {
        $my_data[] = $my_resource_da ta;
        }
        }

        .... you can replace the code located inside the while{} to anything you
        like. My code simply dumps the entire result set into an associative array


        Norm


        Comment

        • Sheldon Glickler

          #5
          Re: Dumbfounded


          "Norman Peelman" <npeelman@cfl.r r.com> wrote in message
          news:%G7Lf.1053 7$_c.569@tornad o.tampabay.rr.c om...[color=blue]
          > "Sheldon Glickler" <sheldonlg@bell south.net> wrote in message
          > news:sA5Lf.2064 $u%.579@bignews 1.bellsouth.net ...[color=green]
          >> I have a script, testsql.php that I run and it works well.
          >>
          >> Here are the guts:
          >>
          >> session_start() ;
          >> require_once("s qlLoginDB.php") ;
          >> mssql_select_db ($database_apbL ogin, $apbLogin);
          >> $_SESSION['curSpeaker'] = '1000129';
          >> query = "SELECT * FROM speakers WHERE iOldSpeakerId=' " .
          >> $_SESSION['curSpeaker'] . "'";
          >> $result = mssql_query($qu ery, $apbLogin);// or die(mssql_error ());
          >> echo "Result: " . $result;
          >>
          >> It gives me a resource ID number.
          >>
          >> When I call a function from another function from the a main page, and[/color]
          > this[color=green]
          >> script is cut and pasted in, the result comes up empty.
          >>
          >> I am at a total loss here.
          >>
          >> Shelly
          >>
          >>[/color]
          >
          > It's giving you a resource id because that's all your asking it for...
          > you
          > also need something like:
          >[/color]

          No, I have the more following this bit where I do an mssql_fetch_ass oc on
          the result. I just posted to the point of where the problem was.

          Shelly


          Comment

          • Sheldon Glickler

            #6
            Re: Dumbfounded

            I want to think all who contributed to helping me. the problem is solved.
            Here is what I **think** the problem was. I was using the require_once()
            for the sqlLoginDB.php. Now, that should have appeared in both the main
            module and in the module that holds the functions --at least that is what I
            thought.

            What I did was to add an assignment to a session variable for the resource
            created by the mssql_connect(. ..) in the sqlLoginDB (and for good measure
            threw in a @session_start( ) at the top of it. I then used that variable
            in the function and all worked well.

            Thank you all once again. Hopefully I can gain enough experience overtimeto
            help others more than they help me.

            Shelly


            Comment

            • Justin Koivisto

              #7
              Re: Dumbfounded

              ZeldorBlat wrote:[color=blue]
              > Justin Koivisto wrote:[color=green]
              >> Sheldon Glickler wrote:[color=darkred]
              >>>
              >>> require_once("s qlLoginDB.php") ;[/color]
              >>
              >> If this is going into a function or included file, it should be an
              >> absolute path. For instance, if the sqlLoginDB.php file is lcoated in
              >> the same directory where this code is found, you should use:
              >>
              >> require_once dirname(__FILE_ _).'/sqlLoginDB.php' ;
              >>
              >> That way, no matter what the current working directory is, the file can
              >> be found.[/color]
              >
              > Absolutely not. This would imply that sqlLoginDB.php lives in the same
              > (internet-accessible) directory as the calling file. Files that you
              > include (database connection code, class definitions, etc.) should live
              > in a directory /outside/ the webserver document tree. Set the include
              > path directive in php.ini appropriately.[/color]

              I think you missed the point of my statemnet. I didn't say do save it
              there... I said *if* it was saved there... The point I was making is
              that you want to use absolute system paths, not relative.

              I've learned that when giving suggestions to solve a problem to focus on
              the specific need at hand. If the OP was asking about a secure or safer
              way of doing things, the reply would have been much different.

              --
              Justin Koivisto, ZCE - justin@koivi.co m

              *** Free account sponsored by SecureIX.com ***
              *** Encrypt your Internet usage with a free VPN account from http://www.SecureIX.com ***

              Comment

              • d

                #8
                Re: Dumbfounded

                "Justin Koivisto" <justin@koivi.c om> wrote in message
                news:43fd2f26$0 $15443$6d36acad @titian.nntpser ver.com...[color=blue]
                > ZeldorBlat wrote:[color=green]
                >> Justin Koivisto wrote:[color=darkred]
                >>> Sheldon Glickler wrote:
                >>>>
                >>>> require_once("s qlLoginDB.php") ;
                > >>
                >>> If this is going into a function or included file, it should be an
                >>> absolute path. For instance, if the sqlLoginDB.php file is lcoated in
                >>> the same directory where this code is found, you should use:
                >>>
                >>> require_once dirname(__FILE_ _).'/sqlLoginDB.php' ;
                >>>
                >>> That way, no matter what the current working directory is, the file can
                >>> be found.[/color]
                >>
                >> Absolutely not. This would imply that sqlLoginDB.php lives in the same
                >> (internet-accessible) directory as the calling file. Files that you
                >> include (database connection code, class definitions, etc.) should live
                >> in a directory /outside/ the webserver document tree. Set the include
                >> path directive in php.ini appropriately.[/color]
                >
                > I think you missed the point of my statemnet. I didn't say do save it
                > there... I said *if* it was saved there... The point I was making is that
                > you want to use absolute system paths, not relative.[/color]

                There are perfectly good reasons for using relative paths as opposed to
                absolute... :)
                [color=blue]
                > I've learned that when giving suggestions to solve a problem to focus on
                > the specific need at hand. If the OP was asking about a secure or safer
                > way of doing things, the reply would have been much different.
                >
                > --
                > Justin Koivisto, ZCE - justin@koivi.co m
                > http://koivi.com/
                > *** Free account sponsored by SecureIX.com ***
                > *** Encrypt your Internet usage with a free VPN account from
                > http://www.SecureIX.com ***[/color]


                Comment

                • Justin Koivisto

                  #9
                  Re: Dumbfounded

                  d wrote:[color=blue]
                  > "Justin Koivisto" <justin@koivi.c om> wrote in message
                  > news:43fd2f26$0 $15443$6d36acad @titian.nntpser ver.com...[color=green]
                  >> ZeldorBlat wrote:[color=darkred]
                  >>> Justin Koivisto wrote:
                  >>>> Sheldon Glickler wrote:
                  >>>>> require_once("s qlLoginDB.php") ;
                  >>>> If this is going into a function or included file, it should be an
                  >>>> absolute path. For instance, if the sqlLoginDB.php file is lcoated in
                  >>>> the same directory where this code is found, you should use:
                  >>>>
                  >>>> require_once dirname(__FILE_ _).'/sqlLoginDB.php' ;
                  >>>>
                  >>>> That way, no matter what the current working directory is, the file can
                  >>>> be found.
                  >>> Absolutely not. This would imply that sqlLoginDB.php lives in the same
                  >>> (internet-accessible) directory as the calling file. Files that you
                  >>> include (database connection code, class definitions, etc.) should live
                  >>> in a directory /outside/ the webserver document tree. Set the include
                  >>> path directive in php.ini appropriately.[/color]
                  >> I think you missed the point of my statemnet. I didn't say do save it
                  >> there... I said *if* it was saved there... The point I was making is that
                  >> you want to use absolute system paths, not relative.[/color]
                  >
                  > There are perfectly good reasons for using relative paths as opposed to
                  > absolute... :)[/color]

                  The way I usually handle it is to set the include_path and then use
                  relative paths. However, when I am not doing that, I like to use things
                  like:

                  dirname(__FILE_ _).'/../../../inc_dir/file.php';

                  that way it is an absolute path according to the execution, but still
                  relative in relation to the script. (If that makes any sense!)

                  --
                  Justin Koivisto, ZCE - justin@koivi.co m

                  Comment

                  Working...