volterony — 2012-08-29T05:50:41-04:00 — #1
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['DOCUMENTROOT'] . '/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['DOCUMENTROOT'] 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['DOCUMENTROOT'] won't work? Do I need to specify something in a php config file or something?
cpradio — 2012-08-29T05:55:05-04:00 — #2
Ensure the DOCUMENT_ROOT is indeed pointing to the location your includes folder is located in.
volterony — 2012-08-29T06:20:43-04:00 — #3
Thanks for getting back to me.
Sorry are you suggesting that I add: var_dump($SERVER['DOCUMENTROOT']); 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['DOCUMENTROOT']); in my controller file?
Thanks for you help.
ryan_mortier — 2012-08-29T06:33:51-04:00 — #4
Make a test.php and then echo var_dump($SERVER['DOCUMENTROOT']) ; to see what the output says.
volterony — 2012-08-29T06:39:07-04:00 — #5
cpradio — 2012-08-29T07:15:31-04:00 — #6
Okay, and what is the file path to your includes folder? Is it /Library/WebServer/Documents/includes?
volterony — 2012-08-29T07:44:31-04:00 — #7
The project path and the include folder (using a Mac):
The path of my controller file:
In the controller file the include path to my database connection file: include $SERVER['DOCUMENTROOT'] . '/includes/db.inc.php';
Is the Document_Root wrong and needs changed? I am running on 127.0.0.1 and not localhost.
cpradio — 2012-08-29T07:55:45-04:00 — #8
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
volterony — 2012-08-29T08:31:25-04:00 — #9
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.
ryan_mortier — 2012-08-29T08:44:08-04:00 — #10
You should read up on apache virtual hosts. It will allow you to have site specific directives, such as the document root.