scope of mysql connections with multiple php snippets

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dino d.

    scope of mysql connections with multiple php snippets

    hi everyone-

    if i have a simple question- if i open a database connection in one
    snippet of php, can i use it in a subsequent snippet in the same php
    file:


    <html>
    <head>
    </head>
    <body>
    ....
    <?php

    //open database here

    ?>

    //more html

    <?php
    //now use open database

    ?>


    i thought this should work but i'm getting errors. thanks for any
    help.

    dino

  • Aggelos

    #2
    Re: scope of mysql connections with multiple php snippets

    ...
    <?php
    >
    //open database here
    >
    ?>
    >
    //more html
    >
    <?php
    //now use open database
    Do you open the DB two times ?
    What errors are you getting? Can you be more specific ?

    Comment

    • Erwin Moller

      #3
      Re: scope of mysql connections with multiple php snippets

      dino d. wrote:
      hi everyone-
      >
      if i have a simple question- if i open a database connection in one
      snippet of php, can i use it in a subsequent snippet in the same php
      file:
      >
      >
      <html>
      <head>
      </head>
      <body>
      ...
      <?php
      >
      //open database here
      >
      ?>
      >
      //more html
      >
      <?php
      //now use open database
      >
      ?>
      >
      >
      i thought this should work but i'm getting errors. thanks for any
      help.
      >
      dino
      Hi,

      Should work.
      If you didn't close the connection, it is still available later in the SAME
      script.
      When PHP reaches the end of the script and stops, it automagically closes
      the connection for you.

      You must have some other issue going on in your script.
      Maybe it helps if you post a real example, so we can see what you are really
      doing.

      Regards,
      Erwin Moller

      Comment

      Working...