Page 1 of 1

Can't connect to MySQL with "require_once"

Posted: Sun Oct 30, 2005 6:30 am
by hawkfire
Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


I'm trying to build a simple auction site and I cannot connect to my database using the require_once command.  This is how I have the command:

Code: Select all

require_once ('mysql_connect.php');
The mysql_connect.php file is quite simple:

Code: Select all

<?php 

// This file contains the database access information. This file also establishes a connection to MySQL and selects the database.

// Set the database access information as constants.
DEFINE ('DB_USER', 'userid');
DEFINE ('DB_PASSWORD', 'pwd');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'dbname');

// Make the connnection and then select the database.
$dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db (DB_NAME);
?>
If I put the code from the mysql_connect.php DIRECTLY into the index.php file, it works fine. when I try to call it seperately with the require_once command, I get no results.

I'm in a HUGE time crunch on this, so any help would be appreciated.


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Sun Oct 30, 2005 6:32 am
by Charles256
switch require once to include("yourpage.php");

Posted: Sun Oct 30, 2005 6:34 am
by mickd
you could also use include_once if you want.

Posted: Sun Oct 30, 2005 6:42 am
by hawkfire
Charles256 wrote:switch require once to include("yourpage.php");
Actually - that helped more than you might guess. I switched my single quotes to double quote, and got results back. I can't seem to get it to work unless I place it in the same folder as index.php, but I should be okay if I just rename the file to something more cryptic. Thanks for your help!!! :D :D

Posted: Sun Oct 30, 2005 6:45 am
by mickd
if you want it in a different folder youll have to specify the path to the file in the include/require statement including the folder.

not sure why double quotes work while single dont...

Posted: Sun Oct 30, 2005 6:50 am
by Charles256
yeah,me doing double quotes was actually a typo :-D