# require($_SERVER['DOCUMENT_ROOT'] help!



## vinc3nt101 (Dec 28, 2006)

Hey, I watched the 3D Buzz php&mysql series like 10 times. Love the tutorials.

I got apache php and mysql very easily set up but I am having a problem with require.

My php works when I do arithmetics, or date, or printing stuff but not with require. This code is an example from 3DBuzz.com tutorials for practicing php.

<?php 
require($_SERVER['DOCUMENT_ROOT'].'/config/config.php');
$connection=mysql_connect($db_host, $db_user, $db_password) or die("error");

echo $db_host;
?>

This is what I put, and theoretically it should print for me $db_host defined in config/config.php. But it doesn't. It doesn't show anything. Infact if I include this code with HTML documents, the HTML won't show either.

Has the syntax for document_root changed for later versions of PHP?

What is the problem? I even shut off my firewall etc. No good.

The only thing I can think of is my root is in C: so is my PHP folder, my apache and MySQL are in program files in their default places. maybe mysql_connect (); doesnt know where to look for the monitor? help please!


----------



## brendandonhu (Jul 8, 2002)

require() should give you an error if it's not working. You could
echo $_SERVER['DOCUMENT_ROOT'] . '/config/config.php'
to see what folder it's looking it.


----------



## vinc3nt101 (Dec 28, 2006)

yea I expected an error as well, but no error either. strange.


----------



## vinc3nt101 (Dec 28, 2006)

EDIT: actually it doesnt matter about the slashes.

it has a problem with the lines

$connection = mysql_connect($db_host, $db_user, $db_password) or die("error connecting");

when i add this into the code it screws up. not sure whats wrong with it.


----------



## brendandonhu (Jul 8, 2002)

[tsg=yourewelcome]yourewelcome[/tsg]


----------



## vinc3nt101 (Dec 28, 2006)

is the function mysql_connect(); from PHP 5.2.0? I don't think it is included because when I add the mysql_connect to the code thats when nothing appears on the page. It doesn't interact with mysql on my computer.

EDIT: YUP my script is terminating at mysql_connect.' anything before it will print.

help me.


----------



## brendandonhu (Jul 8, 2002)

Is there no error printed?
You may need to add

```
error_reporting(E_ALL);
```
to the beginning of your script to show the error messages.

You also might not have compiled PHP with MySQL support - it's no longer built-in by default. You can run phpinfo() and look for a "MySQL" section to find out.


----------



## vinc3nt101 (Dec 28, 2006)

no wonder! how do I compile PHP with mysql?


----------



## brendandonhu (Jul 8, 2002)

Are you using Windows?


----------



## vinc3nt101 (Dec 28, 2006)

yes i am


----------



## brendandonhu (Jul 8, 2002)

You might want to just install WAMP:
http://www.wampserver.com/en/


----------

