SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_SERVER['DOCUMENT_ROOT'] '/includes/db.inc.php';

    Hi there,

    I am working through the Build Database Driven Website with PHP and Mysql by Kevin Yank edition 4.

    I am having a problem connecting to my ijdb database when I use: include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php'; I am able to connect to the database when I don't use the include but have the connection code in my controller file. So the issue is with the $_SERVER['DOCUMENT_ROOT'] which doesn't seem to work?

    In the actual db.inc.php, I have ensured the connection details are correct: $link = mysqli_connect('127.0.0.1', '*****', '*******');

    So is there any reasons why include $_SERVER['DOCUMENT_ROOT'] won't work? Do I need to specify something in a php config file or something?

    Volterony

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,813
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    Add
    PHP Code:
    var_dump($_SERVER['DOCUMENT_ROOT']); 
    Ensure the DOCUMENT_ROOT is indeed pointing to the location your includes folder is located in.
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  3. #3
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi cpradio,

    Thanks for getting back to me.

    Sorry are you suggesting that I add: var_dump($_SERVER['DOCUMENT_ROOT']); to my php config file? Or do I need to add this in each file has an include ?

    Or do I add the line: var_dump($_SERVER['DOCUMENT_ROOT']); in my controller file?

    Thanks for you help.

    Volterony

  4. #4
    SitePoint Zealot
    Join Date
    Nov 2009
    Location
    Ontario, Canada
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Make a test.php and then echo var_dump($_SERVER['DOCUMENT_ROOT']) ; to see what the output says.

  5. #5
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    string(28) "/Library/WebServer/Documents"

  6. #6
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,813
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by volterony View Post
    string(28) "/Library/WebServer/Documents"
    Okay, and what is the file path to your includes folder? Is it /Library/WebServer/Documents/includes?
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  7. #7
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The project path and the include folder (using a Mac):

    Users/MyName/Sites/MyPHP/sitepointphp/chapter7/includes

    The path of my controller file:

    Users/MyName/Sites/MyPHP/sitepointphp/chapter7/admin/index.html

    In the controller file the include path to my database connection file: include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';

    Is the Document_Root wrong and needs changed? I am running on 127.0.0.1 and not localhost.

    Regards
    Volterony

  8. #8
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,813
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by volterony View Post
    Is the Document_Root wrong and needs changed?
    Yes, you will need to edit your apache configuration to point to the directory that contains your includes folder.

    OR, you can change the include to be an absolute path to your /includes/db.inc.php file, like so
    PHP Code:
    include 'C:/Users/MyName/Sites/MyPHP/sitepointphp/chapter7/includes/db.inc.php'
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  9. #9
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi cpradio,

    Yes the absolute path works fine, and should do for now as I am only working through a book project. However I think I would change the DOCUMENT_ROOT if I were publishing this on a real server!

    Really appreciate the time taken to help.

    Best regards
    Volterony

  10. #10
    SitePoint Zealot
    Join Date
    Nov 2009
    Location
    Ontario, Canada
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should read up on apache virtual hosts. It will allow you to have site specific directives, such as the document root.


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
  •