SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: Help Fast!

  1. #1
    Bah, I'll just hack it DoobyWho's Avatar
    Join Date
    Jul 2002
    Posts
    476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help Fast!

    If i've got say...

    PHP Code:
    $MYSQL'SERVER' ] = "localhost";
    $MYSQL['USERNAME'] = "username" 
    and i wanted to use it in say...

    PHP Code:
    function db_connect(){
    global 
    $MYSQL;
    echo 
    $MYSQL['SERVER'];
    echo 
    $MYSQL['USERNAME';

    wouldn't that work? Cause it's not for me!

  2. #2
    SitePoint Member FURY's Avatar
    Join Date
    Sep 2002
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $MYSQL['SERVER'] = "localhost";
    $MYSQL['USERNAME'] = "username";


    function 
    db_connect(){
      global 
    $MYSQL;
      echo 
    $MYSQL['SERVER'];
      echo 
    $MYSQL['USERNAME'];
    }

    db_connect(); 
    That echos localhostusername.

  3. #3
    Bah, I'll just hack it DoobyWho's Avatar
    Join Date
    Jul 2002
    Posts
    476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thats the thing tho. it doesnt!

  4. #4
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    are you trying to connect or echo the variableS?
    Aaron Brazell
    Technosailor



  5. #5
    Bah, I'll just hack it DoobyWho's Avatar
    Join Date
    Jul 2002
    Posts
    476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im just trying to echo the variables from inside the function.

  6. #6
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, it works for me on Windows XP, PHP 4.2.3....

    Aaron
    Aaron Brazell
    Technosailor



  7. #7
    Bah, I'll just hack it DoobyWho's Avatar
    Join Date
    Jul 2002
    Posts
    476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is there a certain something that needs to be turned on ?

  8. #8
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nope register_globals is off on my pc.
    Aaron Brazell
    Technosailor



  9. #9
    Bah, I'll just hack it DoobyWho's Avatar
    Join Date
    Jul 2002
    Posts
    476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hrm very strange.

  10. #10
    Bah, I'll just hack it DoobyWho's Avatar
    Join Date
    Jul 2002
    Posts
    476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i tried just this

    PHP Code:
    <?PHP

    $test 
    "asdasdsad";

    function 
    testing(){
    global 
    $test;
    echo 
    $test;
    }

    testing();
    ?>
    and it echoed.. but the other doesnt..

  11. #11
    SitePoint Enthusiast
    Join Date
    Jan 2003
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What version of PHP/Platform are you running on?

    Also try:
    PHP Code:
    <?PHP
    $MYSQL 
    = array();
    $MYSQL['SERVER'] = "localhost";
    $MYSQL['USERNAME'] = "username";


    function 
    db_connect(){
      global 
    $MYSQL;
      echo 
    $MYSQL['SERVER'];
      echo 
    $MYSQL['USERNAME'];
    }

    db_connect();
    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •