Can't connect to MySQL with "require_once"

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
hawkfire
Forum Newbie
Posts: 14
Joined: Sun Oct 30, 2005 6:20 am

Can't connect to MySQL with "require_once"

Post 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]
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

switch require once to include("yourpage.php");
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post by mickd »

you could also use include_once if you want.
hawkfire
Forum Newbie
Posts: 14
Joined: Sun Oct 30, 2005 6:20 am

Post 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
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post 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...
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

yeah,me doing double quotes was actually a typo :-D
Post Reply