Announcement

Collapse
No announcement yet.

PHP Help

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

  • PHP Help

    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.
    - MrLister

  • #2
    Here's how to do it...

    Here is how you would do something like that:

    In global.php, have a function like:

    PHP Code:
    include("config.php");

    dbconnect()
    function 
    dbconnect() {
        global 
    $dbuser,$dbpass,$dbhost,$database// these are in config.php
        
    $conn mysql_pconnect($dbhost,$dbuser,$dbpass) or die("failed to connect to the database");
        
    mysql_select_db($database) or die("failed to select database");
        return 
    $conn;

    Thats how I would do it.

    Hope this helps.

    -Vic

    Comment


    • #3
      I think that PHP3 requires functions to be defined before they are called.... i think. I may be having flashbacks of C though. =P

      Comment


      • #4
        Originally posted by Max Albert
        I think that PHP3 requires functions to be defined before they are called.... i think. I may be having flashbacks of C though. =P
        You're right: in php3 it is required, but in php4 it isn't anymore

        Comment


        • #5
          alright

          PHP Code:
          include("config.php");

          function 
          dbconnect() {
              global 
          $dbuser,$dbpass,$dbhost,$database// these are in config.php
              
          $conn mysql_pconnect($dbhost,$dbuser,$dbpass) or die("failed to connect to the database");
              
          mysql_select_db($database) or die("failed to select database");
              return 
          $conn;
          }
          dbconnect(); 
          There, happy?

          -Vic

          Comment


          • #6
            No, but I'm content.

            If you want me to be happy, give me a dedicated server at no cost.

            Comment

            widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
            Working...
            X