Linking to MySQL for first time : some problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
munkifisht
Forum Newbie
Posts: 14
Joined: Wed Oct 11, 2006 9:15 am

Linking to MySQL for first time : some problem

Post by munkifisht »

Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Ok, I have set up a MySQL database and I am trying to link to it but I'm having some trouble. I have set up an external file in a config (so it is held in D:\site path\config) folder with the following information:

Code: Select all

<?php
	$db_host = "localhost";
	$db_user = "php";
	$db_password = "123";
	$db_name = "test";
?>
All of which should be correct. I have this script called from another file with the following code:

Code: Select all

<?php
	require($_SERVER["DOCUMENT_ROOT"]."/config/db_config.php");
	$connection = mysql_connect($db_host, $db_user, $db_password) or die("error connecting");
	echo "connection made";
?>
but when I try to connect I get this error::

Code: Select all

Warning: require(D:/Program Files/xampp/htdocs/config/db_config.php) [function.require]: failed to open stream: No such file or directory in D:\Program Files\xampp\htdocs\site\temp_con.php on line 2

Fatal error: require() [function.require]: Failed opening required 'D:/Program Files/xampp/htdocs/config/db_config.php' (include_path='.;d:\Program Files\xampp\php\pear\') in D:\Program Files\xampp\htdocs\site\temp_con.php on line 2
This seems strange to me as all elements of the site are working fine (Apache, php and MySQL) and other readdy built sites I have tried such as gallery2 and xoops work fine.


Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
LiveFree
Forum Contributor
Posts: 258
Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town

Post by LiveFree »

Make sure you have the included file in the exact path which the script listed (in the error msg)
munkifisht
Forum Newbie
Posts: 14
Joined: Wed Oct 11, 2006 9:15 am

Post by munkifisht »

thanks man, and sorry for wasting your time, stupid mistake there, I was one folder out and had forgoten that htdocs was the root of my site. Great I can now start devloping
Post Reply