Web Analytics Made Easy -
StatCounter simple question (very simple) - CodingForum

Announcement

Collapse
No announcement yet.

simple question (very simple)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • simple question (very simple)

    say i have a function link so

    PHP Code:
    <?
    include "config.php";

    $connect mysql_connect($db_host$db_user$db_pass) or die("Could not connect:" mysql_error());
    mysql_select_db('db_name'$connect) or die("Could not connect:" mysql_error());


    ?>
    and in the same code i have a function like so

    PHP Code:
    <?

    $connect 
    mysql_connect($db_host$db_user$db_pass) or die("Could not connect:" mysql_error());
    mysql_select_db('db_name'$connect) or die("Could not connect:" mysql_error());

    function 
    One($db_name$db_host$db_user$db_pass) {

    $connect mysql_connect($db_host$db_user$db_pass) or die("Could not connect:" mysql_error());
    mysql_select_db('db_name'$connect) or die("Could not connect:" mysql_error());

    }


    function 
    Two($db_name$db_host$db_user$db_pass) {

    $connect mysql_connect($db_host$db_user$db_pass) or die("Could not connect:" mysql_error());
    mysql_select_db('db_name'$connect) or die("Could not connect:" mysql_error());

    }

    ?>
    Is it really necessacary to put the $connect?

    i was looking at a script that did this.... and i thought for sure i could use a
    PHP Code:
    global $connect
    , and if i can just use global connect in
    PHP Code:
    mysql_select_db($db_name$connect); 
    or do i just use connect.. can someone please try to clear this up?

  • #2
    I'm confused about something...

    Why would you even have to functions that are exactly the same except for name? I mean signature, return, everything?

    Just doesn't make sense....no need for it....

    further, you could use global $connect, I should think.

    Secondly, you don't even technically NEED "$connect = "

    while the function mysql_connect() does in fact have a return type, it isn't required that you store that in a variable. you could:

    PHP Code:
    <?php
    function One($db_name$db_host$db_user$db_pass) {

       
    mysql_connect($db_host$db_user$db_pass) or die("Could not connect:" mysql_error());
       
    mysql_select_db('db_name') or die("Could not connect:" mysql_error());
    }
    ?>
    HTH,
    -Celt

    Comment


    • #3
      Loren,

      You need to make sure you read our posting guidelines section 2

      http://www.codingforum.net/postguide.htm
      Spookster
      CodingForum Supreme Overlord
      All Hail Spookster

      Comment

      Working...
      X