SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: global.php

  1. #1
    Non-Member MrLister's Avatar
    Join Date
    Feb 2001
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    global.php

    I'm trying to write a script for my own amusement. vBulletin always uses global.php by require("./global.php");. it connects to the database and keeps it connected.
    i'm trying to make something similar. how would i go about making a file similar but ofcourse connects to a database and where ever i put require("./global.php"); it will use that db connection.

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tend to do this too. If php has allow persistent connections turned on (in the php.ini file) then if you connect to MySQL using

    mysql_pconnect()

    you will get a persistent connection. What this means is that the connection will be left open to allow it to be used by other scripts run by that apache process. As an aside, people some people comaplain that when they use persistent connections it degrades performance. However, I think that this is more a problem with tuning Apache and managing the number of child processes and their lifetimes.

    Anyway, just put your database connection code in the globals file and include it in your other scripts using require("global.php");

    Eg:
    PHP Code:
     <?php // global.php
    mysql_pconnect("localhost""usid""pword");
    mysql_select_db("databasename");
    ?>
    Its as simple as that! BTW, I think you will find that the code in vBulletin probably says require("../global.php") which is telling unix that the file is to be found in the parent directory of the current directory.

  3. #3
    Non-Member MrLister's Avatar
    Join Date
    Feb 2001
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh ok. I got it now. Thank you for the help!

  4. #4
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually it's require("./global.php"); - same directory.
    Kevin

  5. #5
    Non-Member MrLister's Avatar
    Join Date
    Feb 2001
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    alright got it


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
  •