Problem with require.

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
sturekdrf
Forum Newbie
Posts: 6
Joined: Wed Jun 13, 2012 11:19 pm

Problem with require.

Post by sturekdrf »

So I can't for the life of me figure out what is wrong in this particular script.

I am getting this error
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'DATABASE_HOST' (1) in /home/content/91/9347091/html/utbgaming/scripts/connect.php on line 6
Error connecting to database_name: Unknown MySQL server host 'DATABASE_HOST' (1)
They are both in the scripts folder. But just doesn't wanna work not really sure why.

Connect.php

Code: Select all

<?php

	require 'app_config.php';
	
mysql_connect("DATABASE_HOST",
					"DATABASE_USERNAME", "DATABASE_PASSWORD")
				or die("<p>Error connecting to database_name: ".mysql_error() . "</p>");
			
			echo "<p>Connected to MySQL!</p>";
			
			mysql_select_db("DATABASE_NAME")
				or die ("<p>Error selecting the database DATABASE_NAME: ".
				mysql_error(). "<p>");
			
echo "<p>Connect to MySQL, using database DATABASE_NAME.</p>";
?>
the required php file: app_config.php

Code: Select all

<?php
define("DATABASE_HOST", "newsis.db.9347091.hostedresource.com");
define("DATABASE_USERNAME", "newsis");
define("DATABASE_PASSWORD", "lollol3");
define("DATABASE_NAME", "newsis");
?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Problem with require.

Post by Celauran »

You're quoting them, so they're being interpreted as strings, not constants.

Code: Select all

define(DATABASE_HOST, 'localhost');
etc.
sturekdrf
Forum Newbie
Posts: 6
Joined: Wed Jun 13, 2012 11:19 pm

Re: Problem with require.

Post by sturekdrf »

Hrmmm did not seem to change anything I tried it a few ways after you posted this.

Code: Select all

define(DATABASE_HOST, 'hostinfo');
define('DATABASE_HOST', 'hostinfo');
define("DATABASE_HOST", 'hostinfo');
define(DATABASE_HOST, "hostinfo");
maybe a few other combos after looking up define to see the proper syntax for it. Saw a few different ways it was done unfortunately none of them is working (just realized that i put require at the top cuz that was the initial issue I thought I was having derp.) of course I used the proper host info for this but to lazy to type it out here lol.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Problem with require.

Post by Celauran »

Did you also change it in your mysql_connect() call?

EDIT: I'm an idiot. You only change it in mysql_connect. You still need the quotes in define()
Post Reply