can't open mysql data base using INCLUDE

This code works fine:

<?php $host='localhost'; $username='xxxrio39_kk4hgy'; $password='nqyzper777'; $database='xxxrio39_abcd'; mysql_connect($host,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); but when I take this: $host='localhost'; $username='xxxrio39_kk4hgy'; $password='nqyzper777'; $database='xxxrio39_abcd'; and save it as db_data.php and then run this <?php include ('db_data.php'); mysql_connect($host,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); I get this: $host="localhost" $username="xxxrio39_kk4hgy" $password="nqyzper777" $database="xxxrio39_abcd" Warning: mysql_connect(): Access denied for user ''@'localhost' (using password: NO) in /home/xxxrio39/public_html/html/tweetdist.php on line 5 Unable to select database why won't it work?

It’s not reading the file for some reason.

What’s the directory structure? Are you on WAMP? If so you’ll need to include it like so:

[PHP]
include “” . $_SERVER[‘DOCUMENT_ROOT’] . “/yourfolder/config.php”;
[/PHP]

I’m pretty sure that if it doesn’t work, you need to define the document_root.

WAMP/XAMPP can be tricky to set up sometimes.

Thanks for your reply scott. I am using shared web hosting. Both the program and the include file are in the same directory:

/public_html/progs

I tried changing path in my program and got an “unable to open file” message for my trouble so with my original code I think it is opening the file.

The thing that boggles my mind is that when all the code was in one file it worked fine, but when I took the code that opens the database and put it in an include file, it quit working.

I do have xampp on my home computer and that is why I wanted to use the include in the first place - so I could develop on my home computer without using FTP every time I made a change. While I wait for more answers I will try it on my home computer and see what results I get.

Sponsor our Newsletter | Privacy Policy | Terms of Service