Page 1 of 1

Problem with require.

Posted: Thu Jun 14, 2012 1:03 pm
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");
?>

Re: Problem with require.

Posted: Thu Jun 14, 2012 1:05 pm
by Celauran
You're quoting them, so they're being interpreted as strings, not constants.

Code: Select all

define(DATABASE_HOST, 'localhost');
etc.

Re: Problem with require.

Posted: Thu Jun 14, 2012 1:32 pm
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.

Re: Problem with require.

Posted: Thu Jun 14, 2012 1:39 pm
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()